calling a nested function in matlab

2 visualizzazioni (ultimi 30 giorni)
Osama Alkurdi
Osama Alkurdi il 13 Feb 2020
Risposto: Walter Roberson il 13 Feb 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?

Risposte (1)

Walter Roberson
Walter Roberson il 13 Feb 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.

Categorie

Scopri di più su Environment and Settings in Help Center e File Exchange

Prodotti


Release

R2018a

Community Treasure Hunt

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

Start Hunting!

Translated by