问题

软件 >> MatLab
Questions in category: MatLab (MatLab).

[MATLAB]有一个4*5矩阵, 编程求出其元素最大值及所处的位置.

Posted by haifeng on 2019-06-29 09:40:26 last update 2019-06-29 11:34:22 | Answers (2) | 收藏


[Exer 1.(2), P.30] 《数学建模与数学实验》

有一个4*5矩阵, 编程求出其元素最大值及所处的位置.

 


以下是学生写的代码, 请改进

function f=zuidazhi(x)
a=1;b=1;c=x(1,1);
for i=1:4
        for j=1:5
           if x(i,j)>c
            a=i;b=j;c=x(i,j);
           end
       end
end
f=[c,a,b]

% for test
% x=rand(4,5)
% zuidazhi(x)