sort rows of a matrix based on their maximum value

Hello,
Consider a 100x10 matrix.
Each 1x10 row has a maximum value.
How can I sort the rows of the matrix in ascending order based only on their maximum value?
Thank you very much.
Best,
Pavlos

 採用された回答

Jan
Jan 2013 年 9 月 11 日

3 投票

A = rand(100, 10);
maxA = max(A, [], 2);
[dummy, index] = sort(maxA);
B = A(index, :);

1 件のコメント

Simon
Simon 2013 年 9 月 11 日
Great! Better solution than mine!
Side note: you may use "~" instead of "dummy".

サインインしてコメントする。

その他の回答 (2 件)

Azzi Abdelmalek
Azzi Abdelmalek 2013 年 9 月 11 日
編集済み: Azzi Abdelmalek 2013 年 9 月 11 日

0 投票

Edit2
[ii,ii]=sort(max(A'))
BB=A(ii,:)

1 件のコメント

Azzi Abdelmalek
Azzi Abdelmalek 2013 年 9 月 11 日
編集済み: Azzi Abdelmalek 2013 年 9 月 11 日
Look at Edit2

サインインしてコメントする。

Simon
Simon 2013 年 9 月 11 日

0 投票

A=randi(100,10,5);
for n = 1:size(A, 1)
B(n,:) = sort(A(n,:));
end

カテゴリ

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

製品

タグ

質問済み:

2013 年 9 月 11 日

Community Treasure Hunt

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

Start Hunting!

Translated by