find where two dataset intersect or get closer

4 Ansichten (letzte 30 Tage)
fransec
fransec am 6 Jun. 2019
Kommentiert: Kevin Rawson am 16 Jun. 2019
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.
untitle.jpg
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.
zoom.jpg
Does anyone know a function which find the closer point between two arrays or datasets?
Thanks a lot!
  2 Kommentare
darova
darova am 7 Jun. 2019
\what if slightly replace data2?
fransec
fransec am 7 Jun. 2019
Sorry, I don't understand your comment..

Melden Sie sich an, um zu kommentieren.

Akzeptierte Antwort

Kevin Rawson
Kevin Rawson am 7 Jun. 2019
Bearbeitet: Kevin Rawson am 7 Jun. 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 Kommentare
fransec
fransec am 7 Jun. 2019
You're right, no problem in the polyxpoly function, it returns an empty set because there is no cross really.
I am trying to use pdist2 function, but i need the indices of the closest point and at the moment I can't find them. Consider that data 1(my data) and data2(the line) have different length...
Kevin Rawson
Kevin Rawson am 16 Jun. 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.

Melden Sie sich an, um zu kommentieren.

Weitere Antworten (0)

Community Treasure Hunt

Find the treasures in MATLAB Central and discover how the community can help you!

Start Hunting!

Translated by