MATLAB: How to find the most minimum value of 100 minimum values

iterationsminimumwhile loop

Dear all,
I have a (100 iterations) while loop, during each iteration the program finds a minimum value,
so I'll have 100 minimum values.How to find the most minimum one of the 100 minimum values?

Best Answer

Mohamed - if your while loop produces a minimum value in each iteration, then just save it to an array/vector. When the code exits the while loop, just find the minimum of that vector. For example
minValuesFound = [];
while someConditionIsTrue
% do some work

% find the minimum

% add the minimum value to the vector
minValuesFound = [minValuesFound ; newMinForThisIteration];
end
% find the overall min
overallMin = min(minValuesFound);
Try something like the above - the trick is to keep track of all minimum values from each iteration and then find the minimum afterwards. Alternatively, you could just keep track of the overall minimum value at each iteration
overallMin = Inf;
while someConditionIsTrue
% do some work
% find the minimum
% is this minimum smaller?
if newMinForThisIeration < overallMin
overallMin = newMinForThisIeration;
end
end
Either way should work for you!