2017-04-21 3 views
0

私はMatlabで2ラインの幾何学的ポイントデータを持っています。私はポイントを介してスプラインを作る別のプログラムにそれらをエクスポートしています。例えばスプラインのランダムな点で温度を計算し、Matlabに送り返します。どのラインポイントが属しているかを見つける - 対応するソートマトリックス

今、私はこのデータを持っており、気温がどのラインに属しているのか分かりません。しかし、私は新しいポイントの座標を取得します。だから私はポイントが属している線を決定し、その情報を使って2つの温度ベクトルを分割する必要があります。

ここでは、使用する '例'を生成するコードを示します。

% Known geometric point data which is read by 3rd program. 
x1 = 0:0.05:1;  y1 = -sin(x1.*(4.*pi))./6; 
x2 = 0:0.05:1;  y2 = sin(x2.*(pi)); 

% 3rd program makes spline from given points. 
xx1 = 0:0.075:1;  xx2 = [0:0.1:1]; 
yy1 = spline(x1,y1,xx1); 
yy2 = spline(x2,y2,xx2); 
XY = [xx1, xx2; yy1, yy2]; 
[Y,I]=sort(XY(1,:)); 

% The program gives me DAT file with the 'new' coordinates of the new 
% points. But the line-up of the points are random. In this example I've 
% merged the coordinates of the two lines mixed them by sorting the X 
% coordinates. 
% The program gives me, for example, the temperature at these points in 
% same order as the new coordinates. But now I'll need to know which line 
% they belong to. 

COORDINATE = XY(:,I); 
TEMPERATURE = [COORDINATE(1,:); rand(1,length(COORDINATE))]; 

目標:

  1. [X1、Y1]または[X2、Y2]に属する座標のポイントを決定します。
  2. TEMPERATUREを[xx1; T1]および[xx2; T2]に対応する。

2本の線は互いに交差しないことに注意してください。しかし、それらは同じx間隔を持つ必要はありません。

答えて

1

MATLABのDATファイルのx座標にスプライン補間を行い、結果のy座標をDATファイルの座標と比較する方法があります。

% get xy coordinates 
xi = COORDINATE(1,:); 
yi = COORDINATE(2,:); 
% spline interpolation for two lines of every x 
yi1 = spline(x1,y1,xi); 
yi2 = spline(x2,y2,xi); 
% compare y coordinates 
d1 = abs(yi1 - yi); 
d2 = abs(yi2 - yi); 
belongToLine1 = d1 <= d2; 
belongToLine2 = d1 >= d2; 
% plot 
plot(COORDINATE(1,belongToLine1),COORDINATE(2,belongToLine1),'ob-'); 
hold on; 
plot(COORDINATE(1,belongToLine2),COORDINATE(2,belongToLine2),'or-'); 
hold off 
legend('line1','line2'); 

enter image description here

(補間を必要とするが限定されていない)別のオプションは、あなたのDATファイルで元のポイントとポイントの間のペアワイズ距離を計算することである。

% number of first line original points 
n1 = length(x1); 
% computing pairwise distance between the splines and original points 
xy = [x1,x2;y1,y2]'; 
D = pdist2(COORDINATE',xy); 
% find closest pair indexes 
[~,idx] = min(D,[],2); 
% determine membership 
belongToLine1 = idx <= n1; 
belongToLine2 = ~belongToLine1; 
% plot 
plot(COORDINATE(1,belongToLine1),COORDINATE(2,belongToLine1),'ob-'); 
hold on; 
plot(COORDINATE(1,belongToLine2),COORDINATE(2,belongToLine2),'or-'); 
hold off 
legend('line1','line2'); 

enter image description here

関連する問題