Finding the array location in the matrix

3 vues (au cours des 30 derniers jours)
Moe
Moe le 27 Avr 2014
Commenté : Moe le 27 Avr 2014
Hi everyone,
Suppose I have a matrix:
b = [8;5;9;12]
and:
max(b) = 12 %12 is in the fourth row
I'm looking for a command line which instead of giving me the maximum value, give it to me as a row number (e.g = 4, not 12).
Can anyone help me please?

Réponse acceptée

Geoff Hayes
Geoff Hayes le 27 Avr 2014
Hi Mohammad,
If the input is a vector, then you can do the following:
[val,idx] = max(b);
where val will be the maximum value of 12 and idx will be the index of 4. Type help max for more details. (It gets a little more complicated when the input is matrix.)
Geoff
  1 commentaire
Moe
Moe le 27 Avr 2014
Thanks again Geoff!

Connectez-vous pour commenter.

Plus de réponses (0)

Catégories

En savoir plus sur Creating and Concatenating Matrices dans Help Center et File Exchange

Community Treasure Hunt

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

Start Hunting!

Translated by