Determining What Calls a Function

28 vues (au cours des 30 derniers jours)
Michael
Michael le 30 Août 2011
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

Réponse acceptée

Lucas García
Lucas García le 30 Août 2011
I use grep for an equivalent version to Edit->Find Files.
  1 commentaire
Michael
Michael le 30 Août 2011
This is what I was looking for! Thanks!

Connectez-vous pour commenter.

Plus de réponses (2)

Fangjun Jiang
Fangjun Jiang le 30 Août 2011
depfun() is used to locate the dependent function from top to down. Not sure if you can utilize it.

Michael
Michael le 30 Août 2011
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 commentaires
Walter Roberson
Walter Roberson le 30 Août 2011
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 le 30 Août 2011
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/

Connectez-vous pour commenter.

Catégories

En savoir plus sur File Operations dans Help Center et File Exchange

Produits

Community Treasure Hunt

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

Start Hunting!

Translated by