如何在 MATLAB 中生成函数依赖项列表? [英] How can I generate a list of function dependencies in MATLAB?

查看:40
本文介绍了如何在 MATLAB 中生成函数依赖项列表?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

为了分发我编写的函数,该函数依赖于我编写的其他函数,这些函数具有自己的依赖关系等等,而不分发我编写的每个 m 文件,我需要弄清楚完整列表依赖项是针对给定的 m 文件的.是否有内置/可免费下载的方法来执行此操作?

In order to distribute a function I've written that depends on other functions I've written that have their own dependencies and so on without distributing every m-file I have ever written, I need to figure out what the full list of dependencies is for a given m-file. Is there a built-in/freely downloadable way to do this?

特别是我对 MATLAB 7.4.0 (R2007a) 的解决方案感兴趣,但如果在旧版本中有不同的方法,请务必在此处添加它们.

Specifically I am interested in solutions for MATLAB 7.4.0 (R2007a), but if there is a different way to do it in older versions, by all means please add them here.

推荐答案

对于较新版本的 Matlab(例如 2007 或 2008),您可以使用内置函数:

For newer releases of Matlab (eg 2007 or 2008) you could use the built in functions:

  1. 提示
  2. 依赖报告和
  3. 覆盖率报告

另一种选择是使用 Matlab 的分析器.该命令是 profile,它还可用于跟踪依赖项.要使用配置文件,您可以执行

Another option is to use Matlab's profiler. The command is profile, it can also be used to track dependencies. To use profile, you could do

>> 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 之前的版本):

If profiler is not available, then perhaps the following two functions are (for pre-MATLAB 2015a):

  1. depfun
  2. depdir

例如

>> deps = depfun('foo');

给出一个结构 deps,其中包含 foo.m 的所有依赖项.

gives a structure, deps, that contains all the dependencies of foo.m.

来自答案 23,较新版本的 MATLAB(2015a 之后)改用 matlab.codetools.requiredFilesAndProducts.

From answers 2, and 3, newer versions of MATLAB (post 2015a) use matlab.codetools.requiredFilesAndProducts instead.

查看答案

感谢@Mike Katz 的评论

Caveats thanks to @Mike Katz comments

  • 请记住,探查器只会向您展示实际使用的文件在那些跑步中,所以如果你不去通过每个分支,你可能有额外的依赖.这依赖报告是一个很好的工具,但是只解决静态依赖路径,仅用于 a 中的文件单个目录.

  • 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 更可靠,但为您提供它所能想到的一切,并且仍然错过 LOAD 和 EVAL.

Depfun is more reliable but gives you every possible thing it can think of, and still misses LOAD's and EVAL's.

这篇关于如何在 MATLAB 中生成函数依赖项列表?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆