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

for c=[5 15]
for hh=[2 7]
ug=c/hh
end
end

3 件のコメント

You need to keep track of the total count in the nested loops and index ug.
count=0
for
for
count=count+1;
ug(count)=c/hh;
end
end
Then you need to keep track of the minimum. A simple if statement will do the trick. Incorporate the above and if you have additional questions ask.
also i need to find for what value of c and hh, i get the minimum value of c/hh.
Thank you very much

サインインしてコメントする。

 採用された回答

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!

その他の回答 (0 件)

カテゴリ

ヘルプ センター および File ExchangeLoops and Conditional Statements についてさらに検索

Community Treasure Hunt

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

Start Hunting!

Translated by