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
0 个评论
采纳的回答
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 Center 和 File Exchange 中查找有关 Loops and Conditional Statements 的更多信息
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!