0
plot([x5],[y5],'-',xout_1(1),yout_1(1),'*',xout_1(2),yout_1(2),'*')

x5 =[125  -263]

y5 =[165  -375]

xout_1 =[135.5049    -127.0045]

yout_1 =[  179.6202  -185.7279]

これは私のプログラムのシナリオです。
ラインからポイント (135.5049,179.6202) を破棄するにはどうすればよいですか? これらの値は、シミュレーションごとに変化します。
そのポイントを削除する方法を誰か教えてください。

ありがとう

4

1 に答える 1

1

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.

于 2012-07-16T11:58:27.893 に答える