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

33 次查看(过去 30 天)
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
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
Matt 2020-8-24
编辑: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?

请先登录,再进行评论。

类别

Help CenterFile Exchange 中查找有关 File Operations 的更多信息

Community Treasure Hunt

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

Start Hunting!

Translated by