获取矩阵中最大值的位置

时间:2013-10-27 23:31:54

标签: matlab matrix

假设我在MATLAB中有以下矩阵:

I=[2 1;4 5];

如何检索最大元素的位置?

3 个答案:

答案 0 :(得分:5)

您可以执行以下操作:

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

>> [row, col]                            

ans =

     2     2

答案 1 :(得分:3)

您可以获得索引如下:

[~, idx] = max(I(:))

然后使用它

I(idx)

答案 2 :(得分:1)

或者您可以使用find

[row, col] = find(I == max(I(:)))
row =  2
col =  2