请问这个matlaB程序是什么意思?function [value,position] = mymax (x)msg = nargchk (1,1,nargin);error (msg);value = x (1);temp = 1;for ii = 2 :length (x)if value < x (ii)value = x (ii);temp = ii;endendif nargout > 1position = temp;end

来源:学生作业帮助网 编辑:作业帮 时间:2024/05/06 05:46:54

请问这个matlaB程序是什么意思?function [value,position] = mymax (x)msg = nargchk (1,1,nargin);error (msg);value = x (1);temp = 1;for ii = 2 :length (x)if value < x (ii)value = x (ii);temp = ii;endendif nargout > 1position = temp;end
请问这个matlaB程序是什么意思?
function [value,position] = mymax (x)
msg = nargchk (1,1,nargin);
error (msg);
value = x (1);
temp = 1;
for ii = 2 :length (x)
if value < x (ii)
value = x (ii);
temp = ii;
end
end
if nargout > 1
position = temp;
end

请问这个matlaB程序是什么意思?function [value,position] = mymax (x)msg = nargchk (1,1,nargin);error (msg);value = x (1);temp = 1;for ii = 2 :length (x)if value < x (ii)value = x (ii);temp = ii;endendif nargout > 1position = temp;end
% 找到输入数组X的最大值value及位置 position
function [value,position] = mymax (x) % 检查输入参数X是否出错msg = nargchk (1,1,nargin); error (msg); % value存储当前最大值,初始化取数组X的第一个值 value = x (1); % temp存储当前最大值位置temp = 1; % 对数组X从2到末尾进行循环
for ii = 2 :length (x) % 判断如有比value 大的值
if value < x (ii) % 更新当前的最大值value及当前最大值位置temp
value = x (ii); temp = ii; end end% 如果输出参数是两个,则temp赋给第二个参数
if nargout > 1 position = temp;end