How to find index of a minimum value starting from the end

1 vue (au cours des 30 derniers jours)
George Ansari
George Ansari le 23 Août 2017
Commenté : José-Luis le 23 Août 2017
I have this code:
A =
1 2 3 4 5 6 7 8 9 1 1 1 1
1 2 3 4 5 6 7 8 9 1 1 1 9
1 2 3 4 5 6 7 8 9 1 1 2 3
1 2 3 4 5 6 7 8 9 1 1 1 1
1 2 3 4 5 6 7 8 9 1 1 1 5
1 2 3 4 5 6 7 8 9 1 1 1 3
1 2 3 4 5 6 7 8 9 1 1 2 3
B = min(A')
B =
1 1 1 1 1 1 1
index = find(A'==B, 1, 'last')
index =
89
What I want is to get the indices of the smallest number starting from the end of each row. The answer should look like this
index =
13 12 11 13 12 12 11
Thanks, George.

Réponse acceptée

José-Luis
José-Luis le 23 Août 2017
A = randi(10,10);
A_min = min(A,[],2);
dummy = bsxfun(@eq,A,A_min);
dummy = bsxfun(@times,dummy,1:size(A,2));
result = max(dummy,[],2)
  2 commentaires
George Ansari
George Ansari le 23 Août 2017
Thanks man!
José-Luis
José-Luis le 23 Août 2017
My pleasure

Connectez-vous pour commenter.

Plus de réponses (0)

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