Finding closest distance between two data set for each point
Show older comments
Hi,
I have two data set. Each of them have 300, 3D (x,y,z) data .
Assume;
first data set =m
second data set=n
Every point in "m" corresponds to 1 point in "n" which have to be the closest one.
I need to find the closest "n" to "m" and calculate the distance between them and i need to do it for all 300 data
I am new with matlab. I think i should use pdist2 but i could not find how.
Thank you...
Accepted Answer
More Answers (1)
Mehmet Volkan Ozdogan
on 29 Mar 2019
0 votes
2 Comments
Walter Roberson
on 29 Mar 2019
Edited: Walter Roberson
on 29 Mar 2019
Assuming that C1 and C2 have 3 columns, giving X Y Z coordinates
d = pdist2(C1, C2);
[mindist, idx] = min(d, [], 2);
for K = 1 : length(idx)
fprintf('C1(%d,:)@(%f,%f,%f) <-> C2(%d,:)@(%f,%f,%f) is distance %f\n', K, C1(K,:), idx(K), C2(idx(K),:), mindist(K));
end
Mehmet Volkan Ozdogan
on 29 Mar 2019
Categories
Find more on Axis Labels in Help Center and File Exchange
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!