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

1 Ansicht (letzte 30 Tage)
for c=[5 15]
for hh=[2 7]
ug=c/hh
end
end
  3 Kommentare

Melden Sie sich an, um zu kommentieren.

Akzeptierte Antwort

Kumar Pallav
Kumar Pallav am 21 Mär. 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!

Weitere Antworten (0)

Kategorien

Mehr zu Loops and Conditional Statements finden Sie in Help Center und File Exchange

Community Treasure Hunt

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

Start Hunting!

Translated by