SELECTING MATRIX ELEMENTS IN DESCENDING ORDER
2 views (last 30 days)
Show older comments
I WANT A PROGRAMME WHERE NUMBERS ARE SELECTED IN DESCENDING ORDER WITH THEIR INDICES (i,j) .
DO NOT ARRANGE THE MATRIX OR CHANGE ANYTHING IN MATRIX.
I JUST WANT SELECTION OF ELEMENTS IN DESCENDING ORDER.
THANKS.
A=[57 60 62 64 69 67 68 63 36 33;
52 45 25 37 49 55 58 49 39 34;
53 45 25 37 48 56 58 50 39 39;
56 48 41 76 159 164 153 158 171 130;
52 47 41 78 123 166 154 154 179 133;
39 43 41 41 45 64 95 93 74 73;
45 43 39 50 52 63 103 86 73 80;
45 35 13 17 30 36 62 54 34 30;
43 34 13 20 31 35 62 51 34 31;
18 19 15 39 85 97 115 78 24 23]
Answers (2)
Mathieu NOE
on 7 Dec 2021
hello
try this
r = row index
c = col index
[value,ind] = sort(A(:),1,'descend');
[r,c] = ind2sub(size(A),ind)
Jan
on 7 Dec 2021
Edited: Jan
on 7 Dec 2021
This can be obtained by the 2nd output of the sort() command.
A=[57 60 62 64 69 67 68 63 36 33;
52 45 25 37 49 55 58 49 39 34;
53 45 25 37 48 56 58 50 39 39;
56 48 41 76 159 164 153 158 171 130;
52 47 41 78 123 166 154 154 179 133;
39 43 41 41 45 64 95 93 74 73;
45 43 39 50 52 63 103 86 73 80;
45 35 13 17 30 36 62 54 34 30;
43 34 13 20 31 35 62 51 34 31;
18 19 15 39 85 97 115 78 24 23];
[~, index] = sort(A(:), 'descend'); % [EDITED] 'descend' as 2nd input
[row,col] = ind2sub(size(A), index)
0 Comments
See Also
Categories
Find more on Matrix Indexing in Help Center and File Exchange
Products
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!