How to use the @ function calling when the function is defined as a variable?

12 ビュー (過去 30 日間)
Robert Jones
Robert Jones 2022 年 8 月 30 日
コメント済み: Robert Jones 2022 年 8 月 30 日
Hello,
I tried the following
Myfunction='runf'
[x,y,z]=@Myfunction
where runf id the real function
It did not work. Is this possible at all?
Thank you

採用された回答

Chunru
Chunru 2022 年 8 月 30 日
MyfunctionStr='rand'; %'runf'
Myfunction = str2func(MyfunctionStr);
%[x,y,z]=@Myfunction
x = Myfunction()
x = 0.7439
  4 件のコメント
Torsten
Torsten 2022 年 8 月 30 日
移動済み: Stephen23 2022 年 8 月 30 日
[sol,fval] = GODLIKE(Myfunction,...
instead of
[sol,fval] = GODLIKE(@Myfunction,...
Robert Jones
Robert Jones 2022 年 8 月 30 日
Excellent!
Thank you!

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

その他の回答 (0 件)

カテゴリ

Help Center および File ExchangeBig Data Processing についてさらに検索

製品


リリース

R2019b

Community Treasure Hunt

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

Start Hunting!

Translated by