How do I list all my dependent m-Files?

I want to generate a list of all the dependent m-files for a particular MATLAB script file that I wrote (just my own functions, not built-in functions). I used to know how to do this, but it has been a few years.

Antworten (5)

Image Analyst
Image Analyst am 4 Jun. 2019

4 Stimmen

Try this:
% List required files and toolboxes. Displays them in the command window or console window (if deployed).
% Sample call
% fullFileName = [mfilename('fullpath'), '.m'];
% DisplayRequiredFunctions(fullFileName)
% It takes a long time to run so that's why I only do it in the development environment.
function DisplayRequiredFunctions(fullFileName)
try
if ~isdeployed
[~, baseFileNameNoExt, ext] = fileparts(fullFileName);
baseFileName = [baseFileNameNoExt, '.m'];
[requiredFileList, toolboxList] = matlab.codetools.requiredFilesAndProducts(fullFileName);
fprintf('Required m-files for %s:\n', baseFileName);
for k = 1 : length(requiredFileList)
fprintf(' %s\n', requiredFileList{k});
end
fprintf('Required MATLAB Toolboxes for %s:\n', baseFileName);
for k = 1 : length(toolboxList)
fprintf(' %s\n', toolboxList(k).Name);
end
end
catch ME
end

3 Kommentare

Josh Philipson
Josh Philipson am 4 Jun. 2019
Dear Image Analyst,
Thank you kindly.
The issue is I have a friend with an old shipwrecked copy of ML, and he doesn't have access to R>2016, and cannot access matlab.codetools.*
I tried the 'depfun' answers but that ran super-slow and I had to abort...
Was looking for an (antiquated) answer that didn't use the new stuff.
If I can't find it, then so be it..
M2C
Josh
Image Analyst
Image Analyst am 5 Jun. 2019
He can give you his code and you can do it.
Mabee
Mabee am 7 Aug. 2019
Dear Image Analyst,
I used matlab.codetools.requiredFilesAndProducts for a similar problem. But I found that it only lists the dependencies that I actually have. It does not seem to list the dependencies that are missing.
I inherited a very complex script that calls long chains of functions and I am trying to figure out which ones are missing.
Thanks for any more advice

Melden Sie sich an, um zu kommentieren.

Image Analyst
Image Analyst am 7 Feb. 2012

2 Stimmen

Try the "Tools->Save and Show Dependency Report" from the MATLAB pulldown menus, or else try these File Exchange submissions:
To me, fdep looks like the most comprehensive.

3 Kommentare

Scott Sather
Scott Sather am 7 Feb. 2012
The Dependency Report is closer to what I want, but it missed a lot of functions that are called, plus it includes a lot of my GUI CreateFcn and Callback functions which are all in the same file. I remember running something within the Command Window and it returned a brief list of the dependent m-files.
Image Analyst
Image Analyst am 7 Feb. 2012
Bearbeitet: per isakson am 7 Aug. 2019
That's true. That's when I discovered fdep. It finds EVERYTHING, including stuff Dependency Report might miss. Make a shortcut on your toolbar and paste this code, then be sure to change the folder in my code from "C:\Program Files\MATLAB\work\UserExamples\fdep" to where YOU have fdep saved.
% Examine an m-file for what toolboxes or other m-files it calls.
addpath(genpath('C:\Program Files\MATLAB\work\UserExamples\fdep'));
% Let the user browse for the m-file.
[baseFileName, folder] = uigetfile('*.*', 'Specify an m-file');
% fprintf(1, 'baseFileName = %s\n', baseFileName);
% Create the full filename.
fullFileName = fullfile(folder, baseFileName);
if exist(fullFileName, 'file')
fprintf(1, 'Running fdep on %s\n', fullFileName);
%cd('C:\Program Files\MATLAB\work\UserExamples\fdep');
% Get its dependencies by passing it to the fdep function.
p=fdep(fullFileName);
p.list();
else
fprintf(1, 'User clicked Cancel. fdep() was not run.\n');
return;
end
Scott Sather
Scott Sather am 7 Feb. 2012
Thanks, this worked for me, but not at first. Then I realized that the functions it wasn't picking up were located in another folder that only gets added to the path within the main script file. After adding that path manually and rerunning your script, the entire set of dependencies appears.
Thanks again.

Melden Sie sich an, um zu kommentieren.

Sean Lynch
Sean Lynch am 5 Nov. 2015

2 Stimmen

depfun has been replaced with matlab.codetools.requiredFilesAndProducts
Kaustubha Govind
Kaustubha Govind am 7 Feb. 2012

0 Stimmen

You can use depfun.

2 Kommentare

Scott Sather
Scott Sather am 7 Feb. 2012
I already tried depfun - it took forever and I eventually had to cancel it. There is a simple method to do this that produces near instant results.
Josh Philipson
Josh Philipson am 4 Jun. 2019
Scott, so what is the simple method?

Melden Sie sich an, um zu kommentieren.

Sean de Wolski
Sean de Wolski am 7 Feb. 2012

0 Stimmen

Perhaps:
doc depfun
?

2 Kommentare

Scott Sather
Scott Sather am 7 Feb. 2012
Have you ever used this yourself?
Sean de Wolski
Sean de Wolski am 7 Feb. 2012
It does expect its input to be a function.

Melden Sie sich an, um zu kommentieren.

Kategorien

Mehr zu Startup and Shutdown finden Sie in Hilfe-Center und File Exchange

Produkte

Gefragt:

am 7 Feb. 2012

Bearbeitet:

am 7 Aug. 2019

Community Treasure Hunt

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

Start Hunting!

Translated by