SELECTING MATRIX ELEMENTS IN DESCENDING ORDER

3 次查看(过去 30 天)
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]

回答(2 个)

Mathieu NOE
Mathieu NOE 2021-12-7
hello
try this
r = row index
c = col index
[value,ind] = sort(A(:),1,'descend');
[r,c] = ind2sub(size(A),ind)

Jan
Jan 2021-12-7
编辑:Jan 2021-12-7
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)

类别

Help CenterFile Exchange 中查找有关 Matrices and Arrays 的更多信息

标签

产品

Community Treasure Hunt

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

Start Hunting!

Translated by