- [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
12 views (last 30 days)
Show older comments
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 Comments
Answers (1)
Star Strider
on 28 Nov 2014
You can get the index of the maximum returned by max by asking the function to return it. From the documentation:
2 Comments
Star Strider
on 28 Nov 2014
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.
See Also
Categories
Find more on Loops and Conditional Statements in Help Center and File Exchange
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!