Create two matrices using the following code:
A = [9, 4, 7; 1, 11, 3]; B = [4, 15, 6, 8, 10, 1, 2, 9, 5, 7, 14, 3]; B = reshape(B,2,3,2);
A = 9 4 7 1 11 3
B(:,:,1) = 4 6 10 15 8 1 B(:,:,2) = 2 5 14 9 7 3
Apply the following procedure to get the elements of a matrix in descending order:
% Elements of A in descending order resultExample1 = sort(A(:),'descend');
resultExample1 = 11 9 7 4 3 1
% Elements of B in descending order resultExample2 = sort(B(:),'descend');
resultExample2 = 15 14 10 9 8 7 6 5 4 3 2 1
I recommend the following books to learn more on matrix sorting in MATLAB.
This book was the winner of a Textbook Excellence Award. Chapter 14 covers matrix sorting, curve fitting, complex numbers, integration, differentiation, and other topics.
MATLAB for Engineers (5th Edition)
This excellent book is especially oriented to engineers and scientists who want to learn MATLAB programming. The third chapter covers matrix sorting and describes several data analysis functions, among other topics.
I also recommend the other tutorials in this series.
- How to Sort a Vector in MATLAB
- How to Sort a 2D Matrix in MATLAB
- How to Sort a Multidimensional Matrix in MATLAB
- How to Sort a 2D Matrix by Column in MATLAB
- How to Sort a 2D Matrix by Row in MATLAB
- How to Get the Elements of a Matrix in Ascending Order in MATLAB
- How to Get the Elements of a Matrix in Descending Order in MATLAB
I hope you have learned how to get the elements of a matrix in descending order in MATLAB. The source code developed in this tutorial is available at this page.