Filter löschen
Filter löschen

Finding column and row number of a element in array

4 Ansichten (letzte 30 Tage)
Sang Heon Lee
Sang Heon Lee am 25 Sep. 2017
Bearbeitet: Stephen23 am 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)

Antworten (1)

Stephen23
Stephen23 am 25 Sep. 2017
Bearbeitet: Stephen23 am 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

Kategorien

Mehr zu Creating and Concatenating Matrices finden Sie in Help Center und File Exchange

Community Treasure Hunt

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

Start Hunting!

Translated by