SELECTING MATRIX ELEMENTS IN DESCENDING ORDER

1 vue (au cours des 30 derniers jours)
HEMRAJ PATEL
HEMRAJ PATEL le 7 Déc 2021
Commenté : Mathieu NOE le 17 Déc 2021
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]
  1 commentaire
Jan
Jan le 7 Déc 2021
Do not:
3. Use all caps or SHOUT in your posts
Thanks.

Connectez-vous pour commenter.

Réponses (2)

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

Jan
Jan le 7 Déc 2021
Modifié(e) : Jan le 7 Déc 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)

Catégories

En savoir plus sur Matrix Indexing dans Help Center et File Exchange

Produits

Community Treasure Hunt

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

Start Hunting!

Translated by