Effacer les filtres
Effacer les filtres

Finding column and row number of a element in array

4 vues (au cours des 30 derniers jours)
Sang Heon Lee
Sang Heon Lee le 25 Sep 2017
Modifié(e) : Stephen23 le 25 Sep 2017
How can I get the number of column and row which certain element of array in located?
For example, for a array or matrix of [1,2,3;4,5,6;7,8,9], how can I obtain the value of row = 3 and column = 3 for finding the maximum value? (which is 9 in this case)

Réponses (1)

Stephen23
Stephen23 le 25 Sep 2017
Modifié(e) : Stephen23 le 25 Sep 2017
>> A = [1,2,3;4,5,6;7,8,9]
A =
1 2 3
4 5 6
7 8 9
>> [val,idx] = max(A(:));
>> [row,col] = ind2sub(size(A),idx)
row =
3
col =
3
>> val
val =
9

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