MATLAB Answers

How to determine the functions used in a long matlab script?

16 ビュー (過去 30 日間)
Zeynab Mousavikhamene
Zeynab Mousavikhamene 2020 年 8 月 23 日
編集済み: Matt 2020 年 8 月 24 日
I am organizing a long matlab script and I need to seprate the functions that this script calss to transfer all to an other folder.
How can list the functions called in the script so I won't need to parse the script?


Matt 2020 年 8 月 23 日
編集済み: Matt 2020 年 8 月 23 日
Hi Zeynab,
There are a couple of different ways to do that:
1) Mathworks has a number of different dependency analyzers. Here's instructions on one for project dependencies
2) Here's instructions on how to use the folder dependency report feature
3) I personally tend to do things programatically, so I use the code tools Required Productions and Files method
Here's one example of how to use #3 (credit goes to the author of the fEx linked below)
% Otherwise find all top-level dependencies for current file
Dep_List = matlab.codetools.requiredFilesAndProducts(SRC);
% Determine which dependencies are matlab bundled functions/toolboxes
IN_matlab = strncmp(matlabroot, Dep_List, length(matlabroot));
% Remove them from the list
Dep_List = Dep_List(~IN_matlab);
An out of date method is to use "depfun", but that will not work in more recent Matlab versions. depfun is used in the below fEx, but I've personally had success in the task you're looking to perform by adapting this fEx to work with the more up to date methods.
To use it, you have to update the method, and then the old method put the parent file at the top of the dependency list while the new methods put it somewhere else, so you have to compensate for that in the processing.

その他の回答 (1 件)

John D'Errico
John D'Errico 2020 年 8 月 23 日
NO. Don't transfer a long list of functions to one folder.
That is a really bad idea. Put the directories that contain your files on your search path. MATLAB can find them all.
You never want to transfer functions supplied by MATLAB to another folder.
  1 件のコメント
Matt 2020 年 8 月 24 日
Hi John,
Zeynab's question wasn't specific, but I took it as an attempt to find dependencies on files/functions that aren't built in. This certainly can be used as part of a method to deploy code, but I'd be interested in a better way to do so.
How do you recommend deploying code or giving it to someone else?


Community Treasure Hunt

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

Start Hunting!

Translated by