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

조회 수: 30 (최근 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
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에서 Get Started with MATLAB에 대해 자세히 알아보기

Community Treasure Hunt

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

Start Hunting!

Translated by