calling a nested function in matlab

3 vues (au cours des 30 derniers jours)
Osama Alkurdi
Osama Alkurdi le 13 Fév 2020
there is a note in a matlab documentation said that "you have to call the nested functions in a certain ways and not by others".
I used the ways in the red below and nothing goes wrong!
can anyone explain to me what is the documentation mean?
  1 commentaire
Spencer Chen
Spencer Chen le 13 Fév 2020
No code. Can't help.

Connectez-vous pour commenter.

Réponses (1)

Walter Roberson
Walter Roberson le 13 Fév 2020
feval() and str2func() only look for functions in the "top level" namespace -- the functions with corresponding .m or .slx or .mdl or .mlapp or .mex* files. They are effectively executed inside the base workspace, not inside the workspace of the executing function. feval() and str2func() will not (reliably) find nested functions or functions that are private to the current file.
In practice what this means is that you should restrict yourself to function handles built with @ and not pass the names of functions to other routines as character vectors or strings, except in some cases where passing a specific function name is a documented option to the function. For example, cellfun(@length, X) and cellfun('length', X) are both valid and have slightly different meanings. See the "backwards compatibility" section of the cellfun documentation.

Catégories

En savoir plus sur Environment and Settings dans Help Center et File Exchange

Produits


Version

R2018a

Community Treasure Hunt

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

Start Hunting!

Translated by