how do i find argmax?

455 ビュー (過去 30 日間)
shikhar
shikhar 2013 年 5 月 21 日
編集済み: James Tursa 2021 年 5 月 18 日
how do i find argmax of, say x=[1 2] without any user defined function?

採用された回答

Walter Roberson
Walter Roberson 2013 年 5 月 21 日
[argvalue, argmin] = min(x);
[argvalue, argmax] = max(x);
  1 件のコメント
shikhar
shikhar 2013 年 5 月 21 日
編集済み: shikhar 2013 年 5 月 21 日
thanks a lot Mr.Roberson

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

その他の回答 (2 件)

Lukasz Laszko
Lukasz Laszko 2019 年 10 月 28 日
編集済み: Lukasz Laszko 2019 年 10 月 28 日
I'm afraid the answer by Walter Roberson is not correct. According to docs the second returned value contains indices of the minimum/maximum values of x. So to find argmax, you need to call x(max_ind),
eg.
x=0.1:.01:4*pi;
[max_val max_ind]=max(cos(x))
argmax=x(max_ind)
-->> max_val=1
-->> argmax=2pi
-->> max_ind=619
  3 件のコメント
James Tursa
James Tursa 2021 年 5 月 17 日
編集済み: James Tursa 2021 年 5 月 18 日
@Lukasz Laszko Argmax is defined as the elements of the domain (i.e., in this case the indexes) where the function (i.e., in this case the vector) obtains the maximum. See these definitions:
Walter's answer is correct according to these definitions.
Your use of cos(x) introduces another function inbetween that was not part of the original question. Did the original question have cos(x) that was subsequently edited out?
Walter Roberson
Walter Roberson 2021 年 5 月 18 日
In the case a function that is effectively f(x(K)) and what you wanted was the x(K) then it would not be unreasonable to take
fx = f(x);
[~, argidx] = max(fx);
argmax = x(argidx);
This adds an extra level of indirection, but it would be a common one.

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


Konstantin
Konstantin 2018 年 6 月 12 日
Great!!!!

カテゴリ

Help Center および File ExchangeGPU Computing についてさらに検索

タグ

Community Treasure Hunt

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

Start Hunting!

Translated by