举个例子,希望有所帮助。代码% 有一个4行5列的矩阵,编程求出其最大值以及最大值所处位置
clc; clear all;
A = rand(4, 5);
m = A(1); ind = [1 1];
for i = 1 : size(A, 1)
for j = 1 : size(A, 2)
if m < A(i, j)
m = A(i, j);
ind = [i j];
end
end
end
m
ind
A(ind(1), ind(2))
结果