2017-04-21 2 views
0

Ich habe eine geometrische Punkt Daten von zwei Zeilen in Matlab. Ich exportiere sie in ein anderes Programm, das einen Spline durch die Punkte macht. Er berechnet zum Beispiel die Temperatur an zufälligen Punkten des Splines und sendet sie an Matlab zurück.Finden Sie, welcher Punkt gehört zu - Sortierung Matrizen entsprechenden

Jetzt habe ich diese Daten und ich habe keine Ahnung, zu welcher Linie die Temperatur gehört. Aber ich bekomme die Koordinaten der neuen Punkte. Also muss ich bestimmen, zu welcher Linie die Punkte gehören und dann diese Informationen verwenden, um den Temperaturvektor in zwei Teile zu teilen.

Hier ist ein Code, der ein 'Beispiel' erzeugt, mit dem man arbeiten kann.

% 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))]; 

Ziel:

  1. fest, welche Punkte von Koordinaten gehören zu [x1, y1] oder [x2, y2].
  2. Split-TEMPERATUR auf [xx1; T1] und [xx2; T2] entspricht # 1.

Beachten Sie, dass sich die beiden Linien niemals kreuzen. Sie haben jedoch nicht notwendigerweise den gleichen x-Abstand.

Antwort

1

Eine Option besteht darin, eine Spline-Interpolation an den x-Koordinaten in Ihrer DAT-Datei in MATLAB durchzuführen und die Ergebniskoordinaten mit denen in Ihrer DAT-Datei zu vergleichen.

% 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

eine weitere Option (die keine Interpolation erfordert, sondern ist begrenzt) ist paarweise Abstände zwischen den ursprünglichen Punkten und die Punkte in der DAT-Datei zu berechnen:

% 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

Verwandte Themen