finding values and ignoring repeats

3 次查看(过去 30 天)
I have a a series of points that end up making up nodes of a tree. this is in a Nx3 matrix of x y z coordinates, I have another list of xyz coordinates of some random points say Mx3, M<<N. I did a NNS to find the closest nodes and have a vector called distvec that is the distance between a point in M and all points in N, from that I go to find(distvec==min(min(distvec))) which would give me the index of the min value in distvec. The only problem is sometimes there are duplicate points in N that end up being the min distance to a point in M so when I do the search it can't find index and I get error. I know this coding of using find is fickle and does anyone know how to ignore the duplicates and just pick the first.

采纳的回答

Roger Stafford
Roger Stafford 2013-8-26
[t,ir] = min(distvec);
[m,ic] = min(t);
I = [ir(ic),ic];
I has the indices of the minimum value in 'distvec' and 'm' is that minimum value. You don't need to use 'find'.

更多回答(1 个)

the cyclist
the cyclist 2013-8-26
I did not follow your text, but maybe the unique() command helps you?

类别

Help CenterFile Exchange 中查找有关 Creating and Concatenating Matrices 的更多信息

标签

Community Treasure Hunt

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

Start Hunting!

Translated by