Is there a Way to Determine Which Function Will be Called Without Actually Calling the Function ?

1 回表示 (過去 30 日間)
Suppose there is a function myfunc that has many instantiations on the path because of overloading. Is there a way to determine which instantion will be called based on the form of the function call without actually calling the function? For example, supppose I have x and y in my workspace. Is there something like this:
which myfunc(x,y)
that returns the full path to the myfunc that would be executed, but doesn't actually call myfunc?

採用された回答

Steven Lord
Steven Lord 2020 年 9 月 7 日
Yes, and in fact you've already given the syntax for that call! See the "Locate Function Invoked with Given Input Arguments" example on the documentation page for the which function.
>> syms x
>> which sin(x)
C:\Program Files\MATLAB\R2020a\toolbox\symbolic\symbolic\@sym\sin.m % sym method
Though since you use the word "return" you'd need to use the function form of which with an output argument.
>> N = which('sin(x)')
  1 件のコメント
Paul
Paul 2020 年 9 月 7 日
Thanks!
I checked the
doc which
page before posting but must not have scrolled down far enough. Should not have missed that.

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

その他の回答 (1 件)

Image Analyst
Image Analyst 2020 年 9 月 7 日
Use
which -all myfunc
Also, try running the attached script.

カテゴリ

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

製品

Community Treasure Hunt

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

Start Hunting!

Translated by