MATLAB Answers

Is there a function for argmax?

280 ビュー (過去 30 日間)
Javier Biera
Javier Biera 2018 年 7 月 5 日
コメント済み: Walter Roberson 2020 年 1 月 7 日
I am looking for a function that selects the argmax value from a vector.
aux = argmax(P); %P is a normal vector
Supposedly there should a function directly called argmax, but is not working (error = Undefined function or variable 'argmax'). Is there any other function? (I am working with the 2017a version).
  5 件のコメント
Stephen Cobeldick
Stephen Cobeldick 2018 年 7 月 5 日
@Javier Biera: did you read the max documentation? It's second output is an index:
[~,idx] = max(...)


回答 (2 件)

Image Analyst
Image Analyst 2018 年 7 月 5 日
It's probably some function that someone wrote, like the person who gave you the code. Ask them for it. Otherwise, can you tell us how aux is used? That may give us some clue as to what argmax gives. Like it really should be nargin (the number of input arguments) or the max value of some matrix inputted into the argument list or who knows what.

Alan 2020 年 1 月 6 日
function y = argmax(x)
[~,y] = max(x);
  3 件のコメント
Walter Roberson
Walter Roberson 2020 年 1 月 7 日
Easier I suspect to return
y == max(x, [], dim);
which would be a logical the same size as the original. That removes the need to worry about different sizes of output for different columns.






Community Treasure Hunt

Find the treasures in MATLAB Central and discover how the community can help you!

Start Hunting!

Translated by