calling a nested function in matlab

조회 수: 1 (최근 30일)
Osama Alkurdi
Osama Alkurdi 2020년 2월 13일
답변: Walter Roberson 2020년 2월 13일
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개)

Walter Roberson
Walter Roberson 2020년 2월 13일
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.

카테고리

Help CenterFile Exchange에서 Environment and Settings에 대해 자세히 알아보기

제품


릴리스

R2018a

Community Treasure Hunt

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

Start Hunting!

Translated by