Effacer les filtres
Effacer les filtres

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

27 vues (au cours des 30 derniers jours)
Zeynab Mousavikhamene
Zeynab Mousavikhamene le 23 Août 2020
Modifié(e) : Matt le 24 Août 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?

Réponse acceptée

Matt le 23 Août 2020
Modifié(e) : Matt le 23 Août 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.

Plus de réponses (1)

John D'Errico
John D'Errico le 23 Août 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 commentaire
Matt le 24 Août 2020
Modifié(e) : Matt le 24 Août 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?

Connectez-vous pour commenter.


En savoir plus sur Get Started with MATLAB dans Help Center et File Exchange

Community Treasure Hunt

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

Start Hunting!

Translated by