MATLAB: Is this not outputting anything

min

function output = MyMin(x)
MIN_VALUE=0;
[m, n]=size(x);
for i=1:length(x)
if MIN_VALUE>x(i)
MIN_VALUE=x(i);
index=i;
output = [MIN_VALUE, index];
end
end

Best Answer

For this to work you need to set your intial MIN_VALUE to inf rather than 0. If its set to zero, it will only make output if you send it a negative number, otherwise it will never go into that if statement.
function output = MyMin(x)
MIN_VALUE=inf;
for i=1:length(x)
if MIN_VALUE>x(i)
MIN_VALUE=x(i);
index=i;
output = [MIN_VALUE, index];
end
end
end