Finding the Index number that corresponds to a specific value
Afficher commentaires plus anciens
Can any one help me how can i determine the index number that coresponds to a value in a matrix? for example, I've this : >> [val2 index2] = max(max(C_IA))
val2(:,:,1) =
31.3781 + 0.0000i
val2(:,:,2) =
30.0139 - 0.0000i
val2(:,:,3) =
27.7915 + 0.0000i
index2(:,:,1) =
1
index2(:,:,2) =
1
index2(:,:,3) =
3
how can i find index2 value which corresponds to the maximum of val2?
in our case here, the solution is to get index2 = 1 as it corresponds to maximum of val2 = 31.3781 but how can i do it in matlab?
I was trying to write something like find(index2 == max(val2)) but it doesn't work.
Réponse acceptée
Plus de réponses (1)
Bruno Pop-Stefanov
le 21 Nov 2013
Modifié(e) : Brewster
le 21 Nov 2013
You can use the find function on your input matrix directly. If I am correct, C_IA should be 3-dimensional. In your case, you would write:
maxval = max(max(max(C_IA)));
index = find(C_IA == maxval);
'index' is the linear index of the max of C_IA. You can then access the element by writing
C_IA(index)
Catégories
En savoir plus sur Loops and Conditional Statements dans Centre d'aide et File Exchange
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!