Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Getting the position of the largest value in a matrix

Tags:

matrix

matlab

Say that I have the following matrix in MATLAB:

I=[2 1;4 5];

How can I retrieve the position of the largest element??

like image 659
Simplicity Avatar asked Jan 18 '26 05:01

Simplicity


1 Answers

You can do as follows:

[value, location] = max(I(:));
[row,col] = ind2sub(size(I), location);

>> [row, col]                            

ans =

     2     2
like image 126
Marcin Avatar answered Jan 20 '26 19:01

Marcin



Donate For Us

If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!