How to get result after loop.

1 view (last 30 days)
Anyone please tell me how I can get the min value of result_Value and corresponding result_z that comes for that min result_Value after the loop end.
clear all;
clc
for i=1:5
a=rand(5,1);
b=2.*a.^2;
[minValb, minIndb]=min(b);
z1=5.*(minIndb);
a=rand(5,1);
c=2.*a.^2;
[minValc, minIndc]=min(c);
z2=5.*(minIndc);
a=rand(5,1);
d=2.*a.^2;
[minVald, minIndd]=min(d);
z3=5.*(minIndd);
result_Value=[minValb; minValc; minVald]
result_z=[z1;z2;z3]
end
At the end I just need to find the min value of result_Value and correspondind result_z that comes from all iterations

Accepted Answer

Mischa Kim
Mischa Kim on 10 Dec 2014
Zahid, you could use instead
result_Value(:,i) = [minValb; minValc; minVald]
result_z(:,i) = [z1;z2;z3]
which saves all the values in a 2D array.

More Answers (0)

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!