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

 采纳的回答

MyfunctionStr='rand'; %'runf'
Myfunction = str2func(MyfunctionStr);
%[x,y,z]=@Myfunction
x = Myfunction()
x = 0.7439

4 个评论

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) ;
it says unrecognizable function Myfunction
[sol,fval] = GODLIKE(Myfunction,...
instead of
[sol,fval] = GODLIKE(@Myfunction,...

请先登录,再进行评论。

更多回答(0 个)

类别

帮助中心File Exchange 中查找有关 Big Data Processing 的更多信息

产品

版本

R2019b

Community Treasure Hunt

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

Start Hunting!

Translated by