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

32 Ansichten (letzte 30 Tage)
Zeynab Mousavikhamene
Zeynab Mousavikhamene am 23 Aug. 2020
Bearbeitet: Matt am 24 Aug. 2020
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?

Akzeptierte Antwort

Matt
Matt am 23 Aug. 2020
Bearbeitet: Matt am 23 Aug. 2020
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.

Weitere Antworten (1)

John D'Errico
John D'Errico am 23 Aug. 2020
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 Kommentar
Matt
Matt am 24 Aug. 2020
Bearbeitet: Matt am 24 Aug. 2020
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?

Melden Sie sich an, um zu kommentieren.

Kategorien

Mehr zu Get Started with MATLAB finden Sie in Help Center und File Exchange

Community Treasure Hunt

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

Start Hunting!

Translated by