请问怎么让具有两列元​素的矩阵按照行之和的​大小顺序排列?。

比如矩阵:A=[1,2;
6,4;
2,7];
A每行的和形成的矩阵就是[3,12,9];
想要的效果是排序之后为
[1,2;
2,7;
6,4];
我看到sort是会对每列排序,达不成这样的效果,请问有什么简单直接一些的方法吗?

 採用された回答

saianan
saianan 2023 年 5 月 17 日

0 投票

可以考虑做行索引排序
更多的可参考
A=[1,2;
6,4;
2,7]
s = sum(A,2);
[~,ind]=sort(s);
B = A(ind,:)
A =
     1     2
     6     4
     2     7
B =
     1     2
     2     7
     6     4
>>

その他の回答 (0 件)

カテゴリ

ヘルプ センター および File ExchangeShifting and Sorting Matrices についてさらに検索

タグ

質問済み:

2023 年 5 月 17 日

回答済み:

2023 年 5 月 17 日

Community Treasure Hunt

Find the treasures in MATLAB Central and discover how the community can help you!

Start Hunting!