How to list all function dependencies in v2016
28 views (last 30 days)
Show older comments
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
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.
Answers (5)
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
Ali Salehi
on 10 Feb 2018
Edited: per isakson
on 6 Aug 2019
1 Comment
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.
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
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
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
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.
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.
2 Comments
DGM
on 5 Apr 2021
Edited: DGM
on 5 Apr 2021
If you've patched fdep, you should upload the patched version on the FEX. You spent more time making a difficult-to-use comment about the changes than it would have taken to just upload the files. It's been over a decade since the original author maintained any of his files. You're not stepping on any toes.
See Also
Categories
Find more on Verification, Validation, and Test in Help Center and File Exchange
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!