MATLAB Answers

How to list all function dependencies in v2016

49 views (last 30 days)
Drew
Drew on 6 May 2016
Commented: Vlad Atanasiu on 11 Sep 2019
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,
matlab.codetools.requiredFilesAndProducts
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 http://undocumentedmatlab.com/blog/parsing-mlint-code-analyzer-output 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 (4)

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?

  0 Comments

Sign in to comment.


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});
end
fprintf('Required MATLAB Toolboxes:\n');
for k = 1 : length(toolboxList)
fprintf(' %s\n', toolboxList(k).Name);
end
end

  2 Comments

Image Analyst
Image Analyst on 9 Oct 2018
Drew, did this work for you? Or not? It works for me.
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: http://www.mathworks.com/matlabcentral/fileexchange/17291. 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.

  2 Comments

Drew
Drew on 9 May 2016
I have used fdep in the past.
Unfortunately fdep also internally requires 'depfun' so v2016 has effectively broken fdep as well.
Thanks for the suggestion though.
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.

Community Treasure Hunt

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

Start Hunting!