How can I search for all occurrences of built-in MATLAB functions called from multiple .m and .mlx files?
59 views (last 30 days)
Show older comments
Henning Søgaard
on 26 Nov 2024 at 10:36
Commented: Henning Søgaard
on 27 Nov 2024 at 8:58
I am teaching numerical methods with MATLAB, and the teaching material I have developed over time includes a vast number of MATLAB files (.m and .mlx) stored in a folder and its subfolders on my laptop.
I want to create a table listing all built-in MATLAB functions called in the code across these MATLAB files. Is there a way to search through all MATLAB files in a folder and its subfolders to identify and tabulate the MATLAB functions used? Ideally, I would like the result in a table format like this:
Function Files
----------------------------------------------
plot <filename_a1>, ..., <filename_an>
fprintf <filename_b1>, ..., <filename_bm>
...
----------------------------------------------
1 Comment
Walter Roberson
on 27 Nov 2024 at 4:26
Unfortunately, https://www.mathworks.com/help/matlab/ref/matlab.codetools.requiredfilesandproducts.html does not list built-in functions.
Accepted Answer
Sumukh
on 27 Nov 2024 at 3:54
It would be helpful to understand what has already been tried to get the result of built-in functions.
While there is no straight-forward way to perform this, you may refer to the following resources to write the code:
- The “dir” function can be used to get the list of files in the current folder and all levels of its subfolders. You can refer to the following documentation to know more:
- Since the built-in functions are used inside the files, the content of each file must be stored and filtered through using regex to identify functions that have the function name with the curly braces. Kindly refer to the following documentation to know more about regex:
- The “exist” function can be used to identify whether the given word in the filtered content is a built-in MATLAB function. The function returns 5 when the given name is a built-in function. You can refer to the following documentation to understand more about the “exist” function:
- The content in the files can be looped through and after filtering through and getting the names of the built-in functions, the data can be formatted as required.
I hope this helps with writing the code.
More Answers (1)
Image Analyst
on 27 Nov 2024 at 4:19
You might try to get a list of functions by using dir() to find all m-files in all subfolders of your MATLAB installation folder. I'm not sure it will find all built-in functions though. It might find a lot of them though. Then loop over all of your own m-files written by you and open them up with something like fileread or readlines and search the contents of your custom written for each of the function names you found.
You might find the FAQ useful: Process a sequence of files
0 Comments
See Also
Products
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!