- [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 次查看(过去 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!