How to list all function dependencies in v2016

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

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일

3 개 추천

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일

1 개 추천

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

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일

1 개 추천

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

Drew, did this work for you? Or not? It works for me.
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일

0 개 추천

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.
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일

0 개 추천

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.

댓글 수: 3

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.
Would be great. I just manually patched, but can't get it running in R2023b.
Fails with this error:
The logical indices in position 1 contain a true value outside of the array bounds.
Error in fdep>FARG_set_entries (line 3267)
nfmt(ix)=par.lint.cyc(ix,2);
Error in fdep>FARG_get_entries (line 3160)
[p,par]=FARG_set_entries(p,par,s,sr,ixb);
Error in fdep>farg (line 2604)
[p,par]=FARG_get_entries(p,par);
Error in fdep>FDEP_get_fun (line 789)
[fa,fap]=farg(fnam,'-s','-d');
Error in fdep>FDEP_get_dep (line 663)
[p,par,dtmp,dmlf,dmod,dmcl,docl]=FDEP_get_fun(p,par,fnam,frot);
Error in fdep (line 145)
[p,par]=FDEP_get_dep(p,par,p.fun{1});
I'm almost certainly sure it is not due to wrong patching.

댓글을 달려면 로그인하십시오.

카테고리

도움말 센터File Exchange에서 File Operations에 대해 자세히 알아보기

질문:

2016년 5월 6일

댓글:

2024년 11월 20일

Community Treasure Hunt

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

Start Hunting!

Translated by