Is there a function for argmax?

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 件のコメント

Geoff Hayes
Geoff Hayes 2018 年 7 月 5 日
Javier - have you tried using max?
Stephen23
Stephen23 2018 年 7 月 5 日
"Supposedly there should a function directly called argmax"
I can't find any reference to a function called argmax in the MATLAB documentation:
Can you please provide a reference for argmax.
Javier Biera
Javier Biera 2018 年 7 月 5 日
Yes, max works, I only need to add a find afterwards. max gives me the maximum value of the vector P. And with a find function I can get the position of the maximum value. Thank you.
Anton Semechko
Anton Semechko 2018 年 7 月 5 日
編集済み: Anton Semechko 2018 年 7 月 5 日
Use syntax
[P_max,id_max]=max(P);
Here, id_max is the index of P_max in P, so that P_max == P(id_max)
Stephen23
Stephen23 2018 年 7 月 5 日
編集済み: Stephen23 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 日

0 投票

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
Alan 2020 年 1 月 6 日

0 投票

function y = argmax(x)
[~,y] = max(x);
end

3 件のコメント

Walter Roberson
Walter Roberson 2020 年 1 月 7 日
function y = argmax(x)
y = find(x == max(x));
end
is closer. But really the meaning needs to be pinned down for the case where x is multidimensional and might contain duplicates.
Alan
Alan 2020 年 1 月 7 日
That is a step more comprehensive, but to cover all the edge cases would need a lot more work. In my opinion, there should be a standard MATLAB function for this.
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.

サインインしてコメントする。

カテゴリ

製品

リリース

R2017a

タグ

質問済み:

2018 年 7 月 5 日

コメント済み:

2020 年 1 月 7 日

Community Treasure Hunt

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

Start Hunting!

Translated by