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

 Accepted Answer

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

4 Comments

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,...

Sign in to comment.

More Answers (0)

Products

Release

R2019b

Asked:

on 30 Aug 2022

Commented:

on 30 Aug 2022

Community Treasure Hunt

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

Start Hunting!