evalin('ca​ller','mfi​lename') does not work.

function out = cdc
out = evalin('caller','mfilename');
end
This fucntion returns the 'cdc', not the caller's mfilename.

2 件のコメント

Rik
Rik 2019 年 5 月 12 日
Why don't you use mfilename directly in the caller? Alternatively you can do something similar with dbstack.
raym
raym 2019 年 5 月 12 日
dbstack does not five the full path to the function.
Now I have used mfilename in caller. I'm just curious about how the mfilename works.

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

 採用された回答

Rik
Rik 2019 年 5 月 12 日
編集済み: Rik 2019 年 5 月 13 日

1 投票

Depending on your release you can get the complete names including the path from dbstack (in v6.5 you couldn't, but already since v7.0 you can). As the doc describes:
dbstack(___, '-completenames')
outputs the fully qualified name of each function in the stack.

その他の回答 (1 件)

Walter Roberson
Walter Roberson 2019 年 5 月 13 日

0 投票

"evalin('caller', expression) finds only variables in the caller's workspace; it does not find functions in the caller. For this reason, you cannot use evalin to construct a handle to a function that is defined in the caller."
If I recall correctly mfilename is implemented by defining a function in each file.

質問済み:

2019 年 5 月 12 日

回答済み:

2019 年 5 月 13 日

Community Treasure Hunt

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

Start Hunting!

Translated by