How to find the most minimum value of 100 minimum values?
2 views (last 30 days)
Show older comments
mohamed aladl
on 17 Jan 2015
Commented: mohamed aladl
on 18 Jan 2015
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?
0 Comments
Accepted Answer
Geoff Hayes
on 17 Jan 2015
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!
4 Comments
Geoff Hayes
on 18 Jan 2015
Mohamed - you may need to provide some more detail as to how your program uses the many matrices and how you have integrated the above "minimum finding code" into it. You had said that there were only 100 iterations - is this not the case?
More Answers (1)
See Also
Categories
Find more on Loops and Conditional Statements in Help Center and File Exchange
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!