Clear Filters
Clear Filters

Finding column and row number of a element in array

4 views (last 30 days)
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)

Answers (1)

Stephen23
Stephen23 on 25 Sep 2017
Edited: Stephen23 on 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

Categories

Find more on Creating and Concatenating Matrices in Help Center and File Exchange

Community Treasure Hunt

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

Start Hunting!