MATLAB: How to write a function to find max & min value in array

arrayfunctionsMATLABmatlab functionmaximumminimum

hi every one I really need your help in this question write a function m.file to find the maximum and minimum number in array *do not use the built in functions in matlab* ? i know how to find it but i don't know how to make a function ?? could anyone help me ?

Best Answer

try it
function [ma mi] = alifun(A)
aw = A(:);
ma = aw(1);
mi = aw(1);
for i1 = 2:numel(aw)
if ma < aw(i1), ma = aw(i1);
elseif mi > aw(i1), mi = aw(i1);
end
end
end