How can I search for all occurrences of built-in MATLAB functions called from multiple .m and .mlx files?
59 次查看(过去 30 天)
显示 更早的评论
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 个评论
Walter Roberson
2024-11-27,4:26
Unfortunately, https://www.mathworks.com/help/matlab/ref/matlab.codetools.requiredfilesandproducts.html does not list built-in functions.
采纳的回答
Sumukh
2024-11-27,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.
更多回答(1 个)
Image Analyst
2024-11-27,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 个评论
另请参阅
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!