如何在MATLAB中生成函数依赖项列表?
时间:2020-03-06 14:22:57 来源:igfitidea点击:
为了分发我编写的依赖于我编写的其他函数的函数,这些函数具有自己的依赖关系,依此类推,而又不分发我曾经编写的每个m文件,我需要弄清楚什么是依赖关系的完整列表给定的m文件。有内置/免费下载的方式可以做到这一点吗?
我特别对MATLAB 7.4.0(R2007a)的解决方案感兴趣,但是如果在旧版本中有其他解决方法,请务必在此处添加它们。
解决方案
对于较新的Matlab版本(例如2007或者2008),我们可以使用内置函数:
- int
- 依赖报告和
- 覆盖率报告
另一种选择是使用Matlab的探查器。该命令是配置文件,它也可用于跟踪依赖关系。要使用个人资料,我们可以
>> profile on % turn profiling on >> foo; % entry point to your matlab function or script >> profile off % turn profiling off >> profview % view the report
如果探查器不可用,则可能具有以下两个功能(对于MATLAB 2015a之前的版本):
- 德普芬
- 德普迪尔
例如,
>> deps = depfun('foo');
给出了一个结构deps,其中包含foo.m的所有依赖项。
在答案2和3中,较新版本的MATLAB(2015年后)使用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.