construct anonymous function that returns the argmax of two symbolic variables

3 ビュー (過去 30 日間)
Leo Simon
Leo Simon 2014 年 4 月 29 日
回答済み: Leo Simon 2014 年 4 月 29 日
Hi, I'd like to construct an anonymous function that returns the argmax of two symbolic variables, e.g.,
syms x y
symMax = @(x,y) max(x,y)
symMax(3,4)
returns
4,
but I don't know how to persuade the anonymous function to return the second argument of max, which is 2.
Parenthetically, I can't do this even when x,y are regular variables, but in that case I have more options to work with.
Thanks very much for any advice.
Leo

採用された回答

Mischa Kim
Mischa Kim 2014 年 4 月 29 日
編集済み: Mischa Kim 2014 年 4 月 29 日
Leo, use
symMax = @(x) [max(x) find(x==max(x))]
symMax([3,4])

その他の回答 (1 件)

Leo Simon
Leo Simon 2014 年 4 月 29 日
Wow, so simple, thanks very much indeed! For my purposes
argmax = @(x)(find(x==max(x)))
is perfect, since I only care about the second argument!

カテゴリ

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

Community Treasure Hunt

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

Start Hunting!

Translated by