为了分发我编写的函数,该函数依赖于我编写的其他函数,这些函数有自己的依赖关系等等,而不分发我曾经编写的每个 m 文件,我需要弄清楚完整列表的依赖项是针对给定的 m 文件的。是否有内置/可免费下载的方式来执行此操作?
特别是我对 MATLAB 7.4.0 (R2007a) 的解决方案感兴趣,但如果在旧版本中有不同的方法,请务必在此处添加它们。
对于较新版本的 Matlab(例如 2007 或 2008),您可以使用内置函数:
林特
依赖报告和
覆盖率报告
另一种选择是使用 Matlab 的分析器。该命令是配置文件,它也可以用于跟踪依赖关系。要使用配置文件,您可以执行
1 2 3 4
| profile on % turn profiling on
foo; % entry point to your matlab function or script
profile off % turn profiling off
profview % view the report |
如果分析器不可用,那么以下两个函数可能是(对于 pre-MATLAB 2015a):
德普芬
目录
例如,
给出了一个结构,deps,它包含了 foo.m.
的所有依赖
从答案 2 和 3 来看,较新版本的 MATLAB(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.
对于 MATLAB 2015a 及更高版本,您最好查看 matlab.codetools.requiredFilesAndProducts
或doc matlab.codetools.requiredFilesAndProducts
因为 depfun 被标记为在未来的版本中被删除。