Get name of functions called inside another function

조회 수: 4 (최근 30일)
M
M 2017년 11월 10일
댓글: Walter Roberson 2017년 11월 10일
Let's say I have a function defined as :
function output = mainFunction(input1, input2)
a=calledFunction1(input1,input2);
b=calledFunction2(input1);
output= a + b ;
end
Is there a way to get the name of the functions that are called inside the mainFunction ? Such that it would return something like :
calledFunctions(mainFunction)
ans =
calledFunction1
calledFunction2
I did not find any existing function that does it.

채택된 답변

Walter Roberson
Walter Roberson 2017년 11월 10일
Because function references can constructed from strings at run time, probably the best way is to use the profiler.
There used to be depfun (or was it dfun), which has been replaced by a long command string that is difficult to remember
  댓글 수: 2
M
M 2017년 11월 10일
Thank you. Actually, using profiler in this way
profile on
mainFunction
p=profile('info');
and then accessing
p.FunctionTable.FunctionName
gives the expected result.
Walter Roberson
Walter Roberson 2017년 11월 10일
In a deleted answer, Stephen Cobeldick pointed to https://www.mathworks.com/help/matlab/ref/matlab.codetools.requiredfilesandproducts.html for static analysis (not run-time analysis)

댓글을 달려면 로그인하십시오.

추가 답변 (0개)

카테고리

Help CenterFile Exchange에서 Characters and Strings에 대해 자세히 알아보기

Community Treasure Hunt

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

Start Hunting!

Translated by