在MatLab中找到每行2D矩阵的排序索引并填充新矩阵 [英] find sorting index per row of a 2D matrix in MatLab and populate a new matrix

查看:451
本文介绍了在MatLab中找到每行2D矩阵的排序索引并填充新矩阵的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我有一个挑战来订购我的矩阵。所提供的函数,如 sortrows 以相反的方式工作...

I have a challenge to order my matrix. The provided functions like sortrows work in the opposite way...

获取此2D矩阵

M =
     40    45    68
     50    65    58
     60    55    48
     57    67    44    
                      ,

目标是找到矩阵 O 表示每行的排序索引(排名),即:

The objective is to find matrix O that indicates the sorting index (rank) per row, i.e.:

O =

     1     2     3
     1     3     2
     3     2     1
     2     3     1
                       .

所以对于第二行 50 是最小元素(1), 65 最大(3), 58 是第二大(2),因此行向量 [1 3 2]

So for the second row 50 is the smallest element (1), 65 the largest (3), and 58 is the second largest (2), therefore row vector [1 3 2].

推荐答案

[~,sorted_inds] = sort(M,2);

会做。

这篇关于在MatLab中找到每行2D矩阵的排序索引并填充新矩阵的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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