distance and matrix unique numbers
Mostrar comentarios más antiguos
Could you, guys, help me please. I have a matrix X X =
2.2000 3.3000
2.2000 3.3000
4.0000 5.0000
3.0000 5.0000
I need to get from this [index,A]
index = [2] or equivalently index = [1]
and
A =
2.2000 3.3000
4.0000 5.0000
3.0000 5.0000
Then I need to calculate the distance to the nearest neighbor within that matrix A. i.e. it will be 3x1 vector of distances.
Any help please. Thanks
Respuestas (4)
the cyclist
el 29 de Sept. de 2011
I don't really understand the output you want. In the first step, do you just want the unique rows? You can do that with:
>> [uniqueX,i,j] = unique(X,'rows')
Read the help file for the unique() function for more details.
jenka
el 29 de Sept. de 2011
0 votos
Fangjun Jiang
el 29 de Sept. de 2011
Do you mean this:
X=[2.2000 3.3000
2.2000 3.3000
4.0000 5.0000
3.0000 5.0000];
index=2;
A=X;
A(index,:)=[];
D=dist(A')
Function dist() requires Neural Network Toolbox. You may also check the function pdist(), which requires Statistics Toolbox.
Walter Roberson
el 29 de Sept. de 2011
0 votos
2 comentarios
jenka
el 29 de Sept. de 2011
Walter Roberson
el 29 de Sept. de 2011
Subtract one of the repeated rows from another: the result will very likely include a non-zero result. Make sure you are using
format long g
as format f might truncate the results.
Categorías
Más información sobre Statistics and Machine Learning Toolbox en Centro de ayuda y File Exchange.
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!