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 ?
조회 수: 2 (최근 30일)
이전 댓글 표시
count=0;
for c=[5 15]
for hh=[2 7]
count=count+1;
ug(count)=c/hh;
end
end
댓글 수: 0
채택된 답변
Voss
2022년 3월 18일
% 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);
disp(min_c);
disp(min_hh);
추가 답변 (0개)
참고 항목
카테고리
Help Center 및 File Exchange에서 Loops and Conditional Statements에 대해 자세히 알아보기
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!