function to find arg max

29 次查看(过去 30 天)
son
son 2014-11-28
评论: Star Strider 2014-11-28
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?

回答(1 个)

Star Strider
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:
  • [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.
  2 个评论
son
son 2014-11-28
these are 4 different functions so it is impossible to use MAX
Star Strider
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 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