Azzera filtri
Azzera filtri

Finding column and row number of a element in array

4 visualizzazioni (ultimi 30 giorni)
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)

Risposte (1)

Stephen23
Stephen23 il 25 Set 2017
Modificato: Stephen23 il 25 Set 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

Categorie

Scopri di più su Creating and Concatenating Matrices in Help Center e File Exchange

Community Treasure Hunt

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

Start Hunting!

Translated by