How to find the most minimum value of 100 minimum values?

2 views (last 30 days)
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?

Accepted Answer

Geoff Hayes
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
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?
mohamed aladl
mohamed aladl on 18 Jan 2015
You are right. After a revision to my code , it works well for 100 and 1000 iterations. Thank you all.

Sign in to comment.

More Answers (1)

Star Strider
Star Strider on 17 Jan 2015
Another option is to use the cummin function.
It might do what you want.

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!