How to compare a matrix row by row with specified condition
1 回表示 (過去 30 日間)
古いコメントを表示
Hello, everyone. I have a data matrix like this
A=[ 5 0 10 15 0.021
5 0 15 20 0.011
10 15 5 0 0.022
15 20 5 0 0.009]
I need to compare each row with all of the other rows. The criteria is that if the 1st and 2nd column of this row is the same as the 3rd and 4th columns of the second row, and if the 3rd and 4th columns of the this row is the same as the 1st and 2nd column of the other row, I need the indices of these two rows.For example,the 1st and 2nd columns of 1st row is 5 and 0,which is the same as the 3rd and 4th columns of third row. And the 3rd and 4th columns of 1st row is 10 and 15,which is the same as the 1st and 2nd columns of the 3rd row. I do not want change the order of my matrix. If anyone knows how can i achieve this, please let me know. thanks a lot
0 件のコメント
採用された回答
José-Luis
2012 年 10 月 30 日
編集済み: José-Luis
2012 年 10 月 30 日
Maybe not the most efficient thing around, but here goes:
A=[ 5 0 10 15 0.021
5 0 15 20 0.011
10 15 5 0 0.022
15 20 5 0 0.009]
m = size(A,1);
find34 = arrayfun(@(x) {find(ismember(A(:,3:4),A(x,1:2),'rows'))},1:m,'uniformoutput',false);
find12 = arrayfun(@(x) {find(ismember(A(:,1:2),A(x,3:4),'rows'))},1:m,'uniformoutput',false);
その他の回答 (0 件)
参考
カテゴリ
Help Center および File Exchange で Creating and Concatenating Matrices についてさらに検索
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!