Arg max of a function
Ältere Kommentare anzeigen
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 Kommentare
dpb
am 21 Nov. 2020
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
am 21 Nov. 2020
dpb
am 22 Nov. 2020
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
am 22 Nov. 2020
Bruno Luong
am 22 Nov. 2020
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
am 28 Nov. 2020
Antworten (1)
Steven Lord
am 21 Nov. 2020
1 Stimme
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.
1 Kommentar
Tina poddar
am 22 Nov. 2020
Kategorien
Mehr zu Multidimensional Arrays finden Sie in Hilfe-Center und File Exchange
Produkte
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!