フィルターのクリア

distance and matrix unique numbers

2 ビュー (過去 30 日間)
jenka
jenka 2011 年 9 月 29 日
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

回答 (4 件)

the cyclist
the cyclist 2011 年 9 月 29 日
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.
  2 件のコメント
jenka
jenka 2011 年 9 月 29 日
the cyclist, it works for a simple example above. However, for some reason, it does not work for my bigger problem, i.e. the uniqueX matrix has many rows that are the same (which I want to avoid). Any suggestion?
jenka
jenka 2011 年 9 月 29 日
also, it appears that the first element in UnigueX does not equal the first element in X. Why? Thanks

サインインしてコメントする。


jenka
jenka 2011 年 9 月 29 日
Hi, well, I tried that but for my data it does not have unique numbers for some reason (maybe it is something to do decimal truncation?) Also, how to then calculate distance vector for matrix uniqueX. Thanks!!!!

Fangjun Jiang
Fangjun Jiang 2011 年 9 月 29 日
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
Walter Roberson 2011 年 9 月 29 日
  2 件のコメント
jenka
jenka 2011 年 9 月 29 日
however, it does give me the same rows. I checked my calculating the nearest neighbor. The results for these "repeated" rows is 0 which is wrong.
Walter Roberson
Walter Roberson 2011 年 9 月 29 日
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.

サインインしてコメントする。

Community Treasure Hunt

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

Start Hunting!

Translated by