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

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

问题描述

为了分配一个函数,我写的这个函数取决于我写的有其自己的依赖关系的其他函数,而不分发我写过的每个m文件,我需要弄清楚什么是完整的列表的依赖关系是给定的m文件。有没有一个内置的/可自由下载的方法来做到这一点?



具体来说,我对MATLAB 7.4.0(R2007a)的解决方案感兴趣,但如果有不同的在旧版本中做的方法,一定要把它们添加到这里。

解决方案

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


  1. mlint

  2. 依赖关系报告和

  3. 覆盖报告

另一个选择是使用Matlab的分析器。该命令是profile,它也可以用于跟踪依赖关系。要使用个人资料,您可以执行

 >> 
>>上的%转动情景档案FOO; %输入到您的matlab函数或脚本
>>关闭%轮廓剖析
>> profview%查看报告

如果profiler不可用,那么以下两个功能可能是(for pre -MATLAB 2015a):


  1. depfun

  2. depdir



    1. 例如,

       >> deps = depfun('foo'); 

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



      从答案 2 3 ,较新版本的MATLAB(post 2015a)使用 matlab.codetools.requiredFilesAndProducts



      查看答案



      编辑:



      请注意@Mike Katz的评论



      • 记住,Profiler只会
        显示实际使用的文件
        在这些运行中,所以如果你不通过每个分支
        ,你可能有
        额外的依赖关系。
        依赖关系报告是一个很好的工具,但是
        只能解析
        的路径静态依赖关系,仅解决
        单个目录中的文件。


      • Depfun更可靠,但给您
        每一个可能的事情,可以想到,
        ,仍然错过了LOAD和EVAL的。 p>




      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?

      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.

      解决方案

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

      1. mlint
      2. dependency report and
      3. coverage report

      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
      

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

      1. depfun
      2. depdir

      For example,

      >> deps = depfun('foo');
      

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

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

      See answers

      EDIT:

      Caveats thanks to @Mike Katz comments

      • 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中生成函数依赖关系列表?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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