how to find minimum value of output corresponds to which input values in a loop/nested loop ? here i want to find minimum value of ug correspond to what value of c and hh ?

1 次查看(过去 30 天)
count=0;
for c=[5 15]
for hh=[2 7]
count=count+1;
ug(count)=c/hh;
end
end

采纳的回答

Voss
Voss 2022-3-18
Here is an alternative to the way I showed in an answer to one of your other questions about this:
% going to keep track of the minimum value of ug as it is calculated.
% initialize the minimum to Inf so that any finite value of ug will
% be less than the "initial minimum" value
min_ug = Inf;
min_c = NaN;
min_hh = NaN;
count=0;
for c=[5 15]
for hh=[2 7]
count=count+1;
ug(count)=c/hh;
% if a new minimum ug value is found,
% store it and the corresponding c and hh:
if ug(count) < min_ug
% (the first time here, min_ug is Inf,
% so ug(count) is guaranteed to be less than min_ug)
min_ug = ug(count);
min_c = c;
min_hh = hh;
end
end
end
disp(min_ug);
0.7143
disp(min_c);
5
disp(min_hh);
7

更多回答(0 个)

类别

Help CenterFile Exchange 中查找有关 Loops and Conditional Statements 的更多信息

Community Treasure Hunt

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

Start Hunting!

Translated by