在matlab中匹配两个矩阵 [英] matching two matrices in matlab

查看:104
本文介绍了在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.

这篇关于在matlab中匹配两个矩阵的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆