对于较新版本的Matlab(例如2007或2008),您可以使用内置函数:
> mlint
>依赖报告和
>覆盖报告
另一个选择是使用Matlab的profiler。命令是profile,它也可以用于跟踪依赖性。要使用配置文件,你可以做
>> profile on % turn profiling on
>> foo; % entry point to your matlab function or script
>> profile off % turn profiling off
>> profview % view the report
如果profiler不可用,则可能以下两个函数(对于pre-MATLAB 2015a):
> depfun
> depdir
例如,
>> deps = depfun('foo');
给出一个结构,deps,它包含foo.m的所有依赖项。
从答案2和3,较新版本的MATLAB(post 2015a)使用matlab.codetools.requiredFilesAndProducts。
见答案
编辑:
警告感谢@Mike Katz的评论
Remember that the Profiler will only
show you files that were actually used
in those runs, so if you don’t go
through every branch, you may have
additional dependencies. The
dependency report is a good tool, but
only resolves static dependencies on
the path and just for the files in a
single directory.
Depfun is more reliable but gives you every possible thing it can think of, and still misses LOAD’s and EVAL’s.