MATLAB Answers

How to list all function dependencies in v2016

45 views (last 30 days)
Drew on 6 May 2016
Commented: tommsch on 21 Oct 2021 at 8:51
They removed the 'depfun' function in v2016a and I'm now at a loss on how to determine my function dependencies. In particular I'm trying to identify rogue functions that are pulling in toolbox dependencies that they shouldn't.
The stated replacement,
does not return nearly the same information as depfun did.
It only returns the user functions called and the required toolboxes for the entire dependency tree.
I can take the list of dependencies returned by 'requiredFilesAndProducts' and then rerun 'requiredFilesAndProducts' on each individual filename with the 'toponly' option to figure out if that particular function has a toolbox dependency but this is incredibly slow and I still can't narrow down the exact toolbox function called as 'requiredFilesAndProducts' does not return matlab functions (why oh why mathworks!!!).
Is there a way, aside from writing my own parser, to retrieve all function dependencies (user, matlab, and built-in) for a function? It boggles my mind that mathworks would have removed this functionality.
Any help would be appreiated.
N.B. The dependency report feature in the GUI is not an option as we need this functionality for our automated tests (that and the dependency report feature doesn't follow all depencies).
  1 Comment
Brian Kirkpatrick
Brian Kirkpatrick on 8 Jun 2017
I've found some success using a call to mlintmex (undocumented, but has a pretty good overview) with the '-callops' option. You can then filter each line of the results with regular expressions to grab each call name. As an extra bonus, built-ins and built-in methods (don't ask me why the tags are different...) can be detected and filtered out in the same way.

Sign in to comment.

Answers (5)

Image Analyst
Image Analyst on 23 Jun 2016
Did you try the Dependency Report that you can get to by clicking on the little down arrow on the title bar of the "Current Folder" panel? Does that work for you?

Ali Salehi
Ali Salehi on 10 Feb 2018
Edited: per isakson on 6 Aug 2019
Use m2html. I tested it on a big project in Matlab 2017b. It works very well. To generate the graphs you will need to install the Graphvis. Follow documentation of m2html, you can see how to do that. Here is a sample result of my project:
  1 Comment
Francis Cossette
Francis Cossette on 21 Aug 2018
I agree, it is a good tool, but it cannot find the nested functions in a basic m-file.

Sign in to comment.

Image Analyst
Image Analyst on 21 Aug 2018
Try this:
% List required files and toolboxes.
if ~isdeployed
fullFileName = [mfilename('fullpath'), '.m'];
[requiredFileList, toolboxList] = matlab.codetools.requiredFilesAndProducts(fullFileName);
fprintf('Required m-files:\n');
for k = 1 : length(requiredFileList)
fprintf(' %s\n', requiredFileList{k});
fprintf('Required MATLAB Toolboxes:\n');
for k = 1 : length(toolboxList)
fprintf(' %s\n', toolboxList(k).Name);
Vlad Atanasiu
Vlad Atanasiu on 11 Sep 2019
Note that functions have to be on the Matlab path (*) in order to be identified by the code above. So run the function to be analyzed before running the code above to ensure all depended functions are indeed on the path.
(*) Matlab > Editor > Home > Environment > Set Path

Sign in to comment.

Image Analyst
Image Analyst on 6 May 2016
Another option, more comprehensive than dependency report is fdep: However it is also a GUI-based tool. I don't remember if there is some function to export a report. If so, perhaps you can alter it to not show the GUI and just call the export function.
Aurelien Queffurust
Aurelien Queffurust on 21 Jun 2016
I agree with you , matlab.codetools.requiredFilesAndProducts is definetely too slow. I have never understood why they had replaced depfun.

Sign in to comment.

Matthew Royal
Matthew Royal on 21 Jan 2021
Edited: Matthew Royal on 21 Jan 2021
Although depfun was removed in 2016a, the internal Matlab dependencies that enable depfun to work were not removed. I was able to make use of these to resurrect fdep and restore almost all of the original functionality to support work on a code conversion project. Please see my posts on the fdep and the GraphViz-like tools for MATLAB pages.
tommsch on 21 Oct 2021 at 8:51
For me the same, please upload the patched version.

Sign in to comment.

Community Treasure Hunt

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

Start Hunting!