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

 Réponse acceptée

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

4 commentaires

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 le 30 Août 2022
Déplacé(e) : Stephen23 le 30 Août 2022
it says unrecognizable function Myfunction
[sol,fval] = GODLIKE(Myfunction,...
instead of
[sol,fval] = GODLIKE(@Myfunction,...
Excellent!
Thank you!

Connectez-vous pour commenter.

Plus de réponses (0)

Catégories

Produits

Version

R2019b

Community Treasure Hunt

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

Start Hunting!

Translated by