find where two dataset intersect or get closer
8 visualizzazioni (ultimi 30 giorni)
Mostra commenti meno recenti
Dear all,
I have two dataset composed by two arrays, xydata and xyfunction. The first is a 10x2 matrix (data1), the second is a 300x2 matrix (data2). In the two columns of both dataset are the x and y coordinates.
Since now I used without problem the function [xi,yi] = polyxpoly(x1,x2,y1,y2), but now the result is an empty matrix
>> whos xydata
Name Size Bytes Class Attributes
xydata 10x2 160 double
>> whos xyfunction
Name Size Bytes Class Attributes
xyfunction 300x2 4800 double
[xi,yi] = polyxpoly(xdata,ydata,xfunction,yfunction)
xi =
0×1 empty double column vector
yi =
0×1 empty double column vector
The problem is that, If i get closer and zoom, I can observe the really the two dataset don't cross each other.
Does anyone know a function which find the closer point between two arrays or datasets?
Thanks a lot!
2 Commenti
Risposta accettata
Kevin Rawson
il 7 Giu 2019
Modificato: Kevin Rawson
il 7 Giu 2019
I'm not understanding how it's a problem if given your two datasets don't cross anywhere that polyxpoly is returning an empty set. It's returning exactly what it should.
If you want to know the closest points between the two datasets, use can use the min and pdist2 functions.
If you want to know the minimum distance between a point of one dataset with a line segment of the other, that's a different problem, one that would have to be examined for 299 x 10 + 300 x 9 cases.
2 Commenti
Kevin Rawson
il 16 Giu 2019
From your example, pdist2 will return a 10x300 array, which by default will contain the Eucliedean distance between every data point in data1 and data2.
If you then evaluate:
[minColValues, minRowIndices] = min(pdist2(data1, data2));
[minVal, minIndex] = min(minColValues);
You will have the closest points to one another:
data1(minRowIndices(minIndex), :)
data2(minIndex, :)
and the distance between them:
minVal
But as I mentioned previously, you might also need/want to evaluate the minimum distance between the line segment between two data points of dataset 1, and a point in dataset 2.
Più risposte (0)
Vedere anche
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!