How to get result after loop.
3 visualizzazioni (ultimi 30 giorni)
Mostra commenti meno recenti
Zahid Iqbal Rana
il 10 Dic 2014
Commentato: Zahid Iqbal Rana
il 10 Dic 2014
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 Commenti
Risposta accettata
Mischa Kim
il 10 Dic 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.
Più risposte (0)
Vedere anche
Categorie
Scopri di più su Loops and Conditional Statements in Help Center e File Exchange
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!