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 中查找有关 Matrices and Arrays 的更多信息
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!