Arg max of a function
古いコメントを表示
I have a doubt regarding finding arg max of a function m = x+y?
function m = equation(x,y)
k = x+y;
[max_value, max_ind] = max(k);
m = k(max_ind);
end
Thank you in advance
6 件のコメント
dpb
2020 年 11 月 21 日
Well, yes, you've tried to compare the LHS to the RHS via the equality "==" operator for some reason that is not at all clear although the immediate error is owing to the fact that neither variable referenced on the LHS is defined.
We don't know what you expect the function to do or return -- there's quite a lot wrong here besides beginning with the minor detail that equation is missspelled altho MATLAB doesn't care, it'll cause difficulty in remembering to use the misspellled version if continue.
But, you pass arguments x,y into the function but immediately overwrite them with local variables -- whassup w/ that?
There's really no way to proceed from this -- tell us what you're trying to do and include a sample of inputs and expected output(s) to help with the explanation.
Tina poddar
2020 年 11 月 21 日
dpb
2020 年 11 月 22 日
But x+y is just a 2D array of constant values -- what do you think is some maximum or function? The question still makes no sense.
And what do you mean, precisely, by the phrase "arg max" that you keep using?
Tina poddar
2020 年 11 月 22 日
Bruno Luong
2020 年 11 月 22 日
No, argmax is the argument at which the function (in your case the array result of plus) is maximized (hence the name ARGMAX)
You should return "max_ind" or "sub2ind(size(k),max_ind)" rather than k(max_ind) (which is btw equal to max_value).
Tina poddar
2020 年 11 月 28 日
回答 (1 件)
Steven Lord
2020 年 11 月 21 日
1 投票
The operator + does not and cannot return two output arguments. Nor can its functional form, plus.
As a hint, take a look at the examples on the documentation page for the max function and see if you can adapt one of those to your needs.
カテゴリ
ヘルプ センター および File Exchange で Multidimensional Arrays についてさらに検索
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!