- [M,I] = max(_) finds the indices of the maximum values of A and returns them in output vector I, using any of the input arguments in the previous syntaxes. If there are several identical maximum values, then max returns the index of the first one.
function to find arg max
조회 수: 26 (최근 30일)
이전 댓글 표시
Hello, i have a problem. please help
we have x1, x2, x3, x4 are different functions of ' t ' and f1, f2, f3, f4 are also different.
t=1:50;
C1=f1(x1)
C2=f2(x2)
C3=f3(x3)
C4=f4(x4)
for t=1:50
C=max([C1 C2 C3 C4])
end
how to find x which cause C max?
댓글 수: 0
답변 (1개)
Star Strider
2014년 11월 28일
You can get the index of the maximum returned by max by asking the function to return it. From the documentation:
댓글 수: 2
Star Strider
2014년 11월 28일
Your question and code lack some necessary information. You are iterating through ‘t’, but your ‘f1...f4’ functions are of ‘x1...x4’ which are different functions of ‘t’ but not explicitly so in the code you posted to create ‘C1...C4’.
I got the impression that you intended to create one value for ‘C1...C4’ in each iteration of your loop, so then each ‘C1...C4’ is a scalar.
I inferred:
for t = 1:50
C1=f1(x1(t));
C2=f2(x2(t));
C3=f3(x3(t));
C4=f4(x4(t));
[C,I]=max([C1 C2 C3 C4]);
Cmax(t) = [C I];
end
so that for every value of ‘t’ you would get the maximum as ‘C’ and the function that produced it in ‘I’.
If that is not what you are doing in your loop, you need to provide a more specific description.
참고 항목
카테고리
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!