在matlab中匹配两个矩阵

问题描述:

假设我有两个矩阵 p

p =
 1     3     6     7     3     6
 8     5    10    10    10     4
 5     4     8     9     1     7
 5     5     5     3     8     9
 9     3     5     4     3     1
 3     3     9    10     4     1

然后将矩阵 p 的列按升序排序

then after sorting the columns of matrix p into ascending order

y =  
 1     3     5     3     1     1
 3     3     5     4     3     1
 5     3     6     7     3     4
 5     4     8     9     4     6
 8     5     9    10     8     7
 9     5    10    10    10     9

我想知道,给定 y 中的值,它在 p

I want to know, given a value from y, what its row was in p

ex:位于第6行第1列的矩阵 p 中的值3

ex: the value 3 which is in matrix p located in row 6 column 1

然后将其排序后位于第2行第1列的矩阵 y

then after sorting it located in matrix y in row 2 column 1

所以我想最后在矩阵 y 中排序后的值,该值最初在矩阵 p

So I want at the end the values after sorting in matrix y, where it was originally in matrix p

只需使用 sort 的第二个输出:

Just use second output of sort:

[y ind] = sort(p);

您想要的结果(每个值的原始行)在矩阵 ind 中.

Your desired result (original row of each value) is in matrix ind.