3

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: 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:

A = [5  0 10 15  *;
     *  *  *  *  *;
     10 15 5  0  *;
     *  *  *  *  *];

As you can see:

  • 1st and 2nd element on row 1 are equal to 3rd and 4th of row 3
  • 3rd and 4rd element on row 1 are equal to 1st and 2nd of row 3

I do not want change the order of my matrix.

4

1 回答 1

1

ismember可以这样做:

[~,b]=ismember(A(:,1:4),A(:,[3 4 1 2]),'rows');
ind = find(b);
ind(:,2) = b(ind(:,1));

ind将包含冗余条目(例如[1 2][2 1]),因为您的标准是对称的,您可以使用以下方法过滤它们:

ind = unique(sort(ind,2),'rows')
于 2012-10-30T19:47:22.153 回答