How to list all function dependencies in v2016

29 ビュー (過去 30 日間)
Drew
Drew 2016 年 5 月 6 日
コメント済み: tommsch 2021 年 10 月 21 日
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 件のコメント
Brian Kirkpatrick
Brian Kirkpatrick 2017 年 6 月 8 日
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.

サインインしてコメントする。

回答 (5 件)

Image Analyst
Image Analyst 2016 年 6 月 23 日
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 2018 年 2 月 10 日
編集済み: per isakson 2019 年 8 月 6 日
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 件のコメント
Francis Cossette
Francis Cossette 2018 年 8 月 21 日
I agree, it is a good tool, but it cannot find the nested functions in a basic m-file.

サインインしてコメントする。


Image Analyst
Image Analyst 2018 年 8 月 21 日
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 件のコメント
Image Analyst
Image Analyst 2018 年 10 月 9 日
Drew, did this work for you? Or not? It works for me.
Vlad Atanasiu
Vlad Atanasiu 2019 年 9 月 11 日
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
Image Analyst 2016 年 5 月 6 日
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 件のコメント
Drew
Drew 2016 年 5 月 9 日
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 2016 年 6 月 21 日
I agree with you , matlab.codetools.requiredFilesAndProducts is definetely too slow. I have never understood why they had replaced depfun.

サインインしてコメントする。


Matthew Royal
Matthew Royal 2021 年 1 月 21 日
編集済み: Matthew Royal 2021 年 1 月 21 日
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 件のコメント
DGM
DGM 2021 年 4 月 5 日
編集済み: DGM 2021 年 4 月 5 日
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.
tommsch
tommsch 2021 年 10 月 21 日
For me the same, please upload the patched version.

サインインしてコメントする。

カテゴリ

Help Center および File ExchangeVerification, Validation, and Test についてさらに検索

Community Treasure Hunt

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

Start Hunting!

Translated by