Finding where a m file or a function is called in a folder with subfolders and many other m files?

I have a 'xyz.m' file which contains a function with the same name, and I want to find where it has been called in a folder full of other m files. Can I do that easily and fast?Thanks a lot.

Answers (1)

If you mean which function is calling xyz.m, you can try adding the following line in xyz.m
evalin('caller','mfilename')
That should display the m file which called xyz()

5 Comments

thanks for your response.
In such case Id have to run all the scripts which are independent of each other, and each time id have to set up the code.
I wanted to know if matlab can search into certain amount of m files located in a certain path and see if this function or this certain word 'xyz' has been used.
Do you mean you have several functions that are stored in multiple xyz.m files?
Or do you want to see which file contains a local function or variable with the name xyz?
For the first, which -all is an excellent start, while the second will take a lot more work. You can adapt some of the functions in this thread, although that might take some work.
the second one. Ok I will take a look into that. Thanks.
That should be a lot easier on windows file search or macos finder search.
The OS tool will not be able to distinguish between comment and code. But it is a good idea to filter out files that don't contain the search string anyway, before parsing variable and function names.

Sign in to comment.

Categories

Products

Release

R2020a

Asked:

on 23 Nov 2020

Commented:

Rik
on 24 Nov 2020

Community Treasure Hunt

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

Start Hunting!