Reputation: 1
I have two matrices in Matlab both are almost similar except that the columns of both the matrices appear at different column number.
For example, enter image description here I need to find that each column of x appears at which column number of A. Any help or idea is highly appreciated.
ismember function only finds if the columns are present in the other matrix or not.
Upvotes: 0
Views: 101
Reputation: 158
I assume with your example that your matrices (say A and B, dimensions n x p) are boolean (you don't say it in your question).
In this case, here is a simple trick : compute the p x p matrix M=A^TB (transpose of A times B) and look for the entries equal to n... Writing P=(M>=n), you get a permutation matrix (one 1 per row and per column ; all the other entries being equal to 0). Then apply this matrix P to the column vector (1,2,.... p) to obtain the permutation array.
Upvotes: 0