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

 Accepted Answer

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

1 Comment

Great! Better solution than mine!
Side note: you may use "~" instead of "dummy".

Sign in to comment.

More Answers (2)

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

Categories

Products

Tags

Asked:

on 11 Sep 2013

Community Treasure Hunt

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

Start Hunting!