Determining What Calls a Function

19 次查看(过去 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.

更多回答(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