How to get result after loop.

3 visualizaciones (últimos 30 días)
Zahid Iqbal Rana
Zahid Iqbal Rana el 10 de Dic. de 2014
Comentada: Zahid Iqbal Rana el 10 de Dic. de 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

Respuesta aceptada

Mischa Kim
Mischa Kim el 10 de Dic. de 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.

Más respuestas (0)

Categorías

Más información sobre Loops and Conditional Statements en Help Center y File Exchange.

Community Treasure Hunt

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

Start Hunting!

Translated by