sort each row of a matrix in a descending order

5 views (last 30 days)
Suppose I have a matrix
[1 2 3
4 5 6
7 8 9]
I want to sort each row in a descending order so that it will be
[3 2 1
6 5 4
9 8 7]

Accepted Answer

Stephen23
Stephen23 on 15 Jul 2022
Edited: Stephen23 on 15 Jul 2022
A = [1 2 3; 4 5 6; 7 8 9]
A = 3×3
1 2 3 4 5 6 7 8 9
B = sort(A,2,'descend')
B = 3×3
3 2 1 6 5 4 9 8 7

More Answers (0)

Categories

Find more on Shifting and Sorting Matrices in Help Center and File Exchange

Tags

Products


Release

R2022a

Community Treasure Hunt

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

Start Hunting!