How to get result after loop.

3 次查看(过去 30 天)
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

采纳的回答

Mischa Kim
Mischa Kim 2014-12-10
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.

更多回答(0 个)

类别

Help CenterFile Exchange 中查找有关 Loops and Conditional Statements 的更多信息

Community Treasure Hunt

Find the treasures in MATLAB Central and discover how the community can help you!

Start Hunting!

Translated by