举个例子:
>> A=[1 2 3 ;4 5 6]
A = 1 2 3 4 5 6
>> max(max(A))
ans = 6
>> [x y]=find(A==max(max(A)))
x = 2
y = 3
>> 找到最大元素是6,对应位置是x=2,y=3,就是第2行,第3列。
[C,I] = max(...) finds the indices of the maximum values of A, and returns them in output vector I. If there are several identical maximum values, the index of the first one found is returned.
C为最大值,I为位置
追问如果是多维的话就不行了,max函数只求各列的最大值
追答哦,你要多维的呀,你就可以这样:
yourmat=rand(9);
temp=yourmat;
while(length(temp)~=1)
temp=max(temp);
end
[index1,index2]=find(yourmat==temp);
disp(['the max value is: ' num2str(temp)]);
disp(['the position is: (' num2str(index1) ',' num2str(index2) ')']);
这个坐标仅适合于2维的,更多维的可能要再麻烦一些,不过这个求最大值的是对多少维都适用的。