If you want to remove check if the points fall on the line, do this:
slope = (y5(2) - y5(1)) / (x5(2) - x5(1)); %# Slope of main line
thr = 1e-6; %# Threshold to check points
idx = (abs((yout_1 - y5(1)) ./ (xout_1 - x5(1)) - slope) < thr) & ...
(xout_1 > min(x5) & xout_1 < max(x5));
Now idx
is a logical vector that has '1's where the point is on the line, and '0' otherwise. To plot these points, use logical indexing:
plot(x5, y5, '-', xout_1(idx), yout_1(idx), '*')
This will work for any number of points, i.e you can add as many points as you want to xout_1
and yout_1
, and it'll plot only those falling on the line.
P.S
There is no need in enclosing x5
and y5
in brackets, they are already a vector.