Store Output Values from All Iterations obtained by nested for loop and display minimum output and it correspond to which input values ?

1 visualización (últimos 30 días)
for c=[5 15]
for hh=[2 7]
ug=c/hh
end
end
  3 comentarios
Vedant Chauhan
Vedant Chauhan el 17 de Mzo. de 2022
also i need to find for what value of c and hh, i get the minimum value of c/hh.

Iniciar sesión para comentar.

Respuesta aceptada

Kumar Pallav
Kumar Pallav el 21 de Mzo. de 2022
Hi,
min=10000;
for c=[5 15]
for hh=[2 7]
ug=c/hh;
if ug<min
min=ug;
cAns=c;
hhAns=hh;
end
end
end
The above code will store the minimum in variable 'min' and the corresponding inputs in 'cAns' and 'hhAns'.
Hope it helps!

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