calling a nested function in matlab
2 ビュー (過去 30 日間)
古いコメントを表示
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
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.
0 件のコメント
参考
カテゴリ
Help Center および File Exchange で Startup and Shutdown についてさらに検索
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!