sort a 2x4 matrix
Show older comments
I have 2x4 matrix and would like to sort the first row from smallest number to largest number, but I would also like the second row to follow along.
V=[9 3 5 2; 30 49 22 354]
Iwant=[2 3 5 9; 354 49 22 30]
Accepted Answer
More Answers (1)
Davide Figoli
on 9 May 2019
you could try doing:
V=[9 3 5 2; 30 49 22 354];
V_orderd=[];
V_ordered(1,:)=sort (V(1,:));
V_ordered(2,:)=sort(V(2,:),'descend');
Categories
Find more on Shifting and Sorting Matrices in Help Center and File Exchange
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!