Determining What Calls a Function

조회 수: 28 (최근 30일)
Michael
Michael 2011년 8월 30일
Is there a function that I could run in command line that will search with in my path to find all of the functions that call a particular m-file?
I need to create a function that will take in an m-file name and will output the layers of function that are called to get to the function in questions. Basically a function tree starting with lowest level and working upward.
Thanks, -Mike

채택된 답변

Lucas García
Lucas García 2011년 8월 30일
I use grep for an equivalent version to Edit->Find Files.
  댓글 수: 1
Michael
Michael 2011년 8월 30일
This is what I was looking for! Thanks!

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

추가 답변 (2개)

Fangjun Jiang
Fangjun Jiang 2011년 8월 30일
depfun() is used to locate the dependent function from top to down. Not sure if you can utilize it.

Michael
Michael 2011년 8월 30일
Thanks for quick response!
I have looked into that and I need to go bottom to up. Is there a way to do something similar to Edit->find file, but with commands instead?
  댓글 수: 2
Walter Roberson
Walter Roberson 2011년 8월 30일
Going bottom up would be less efficient, as it would need to examine each file multiple times.
Going top-down would be more efficient: only the (potentially) called files would need to be examined.
You could also do a one-pass algorithm over all of the files in any order, provided that you built a tree structure, hooking together the pieces as more information became available.
One question I would ask: if you have file A.m that contains a function A_B that calls your target function C, but A never calls A_B, then if you work bottom-up you are going to have to flag A even that it has no actual path to get to C. Is that desirable?
Are callbacks involved in your code? If so are all of the callbacks in the form of either @function_handle or {@function_handle, arg1, arg2, ...} -- or are some of the callbacks coded as strings? The ones coded as strings are a super nuisance to parse out properly.
If you use eval() or feval() or evalc() in your code, getting the calling tree right can be literally impossible. Though, truth to tell, the same tractability problem can occur for structures with dynamic field names that have a subfield that is a function handle.
When you are doing your parsing, please keep in mind that timer callbacks are executed in the context of the base workspace, not in the context of the workspace the callback was defined in.
Abandon Hope, All Ye Who Are Re-Entrant Here.
Fangjun Jiang
Fangjun Jiang 2011년 8월 30일
I thought of Edit->Find file too. I heard the MATLAB Editor API is available in R2011a but I have not been able to try it yet.
http://blogs.mathworks.com/desktop/2011/05/09/r2011a-matlab-editor-api/

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

카테고리

Help CenterFile Exchange에서 File Operations에 대해 자세히 알아보기

제품

Community Treasure Hunt

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

Start Hunting!

Translated by