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

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 件のコメント

Robert Jones
Robert Jones 2022 年 8 月 30 日
移動済み: Stephen23 2022 年 8 月 30 日
I tried this and it did not work. not sure what I am doing wrong.
Thank you
MyfunctionStr='rand'; %'runf'
Myfunction = str2func(MyfunctionStr);
[sol,fval] = GODLIKE(@Myfunction,...
transpose(variable_min_values(:,1)), transpose(variable_max_values(:,1)),...
[],...
'display', 'off','numobjectives', 2) ;
Robert Jones
Robert Jones 2022 年 8 月 30 日
移動済み: Stephen23 2022 年 8 月 30 日
it says unrecognizable function Myfunction
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 件)

カテゴリ

ヘルプ センター および File ExchangeBig Data Processing についてさらに検索

製品

リリース

R2019b

質問済み:

2022 年 8 月 30 日

コメント済み:

2022 年 8 月 30 日

Community Treasure Hunt

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

Start Hunting!

Translated by