Info

This question is locked. 편집하거나 답변을 올리려면 질문을 다시 여십시오.

How to check whether a name is a locally accessible function?

조회 수: 44 (최근 30일)
Adil
Adil 2025년 9월 24일 10:05
Locked: Steven Lord 2025년 9월 27일 13:48
How to check whether a name is a locally accessible function and only locally accessible?
For example, with
function out = top_level_function(name)
% ???
function helper2
end
end
function helper1
end
Desired:
>> top_level_function('helper1')
>> ans =
1
>> otherwise_valid_function(); % executes
>> top_level_function('otherwise_valid_function')
>> ans =
0
isa(eval(['@',name]),'function_handle') with the necessary not file for [SL: removed spam link], not builtin check at the same time probably works in the case where there is no local name shadowing but I am also wondering if that can permit name to be evaluated as an expression without it being a function name. And also what to do when there is local name shadowing?
[SL: removed link that looked like spam]

채택된 답변

Matt J
Matt J 2025년 9월 24일 10:22
편집: Matt J 2025년 9월 24일 10:33
One way,
function tf = top_level_function(name)
s=functions(str2func(name));
tf=strcmp( s.type , "scopedfunction") ;
end

추가 답변 (0개)

This question is locked.

카테고리

Help CenterFile Exchange에서 Get Started with MATLAB에 대해 자세히 알아보기

태그

제품

Community Treasure Hunt

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

Start Hunting!

Translated by