首页
学习
活动
专区
圈层
工具
发布
社区首页 >问答首页 >我在哪里使用工具箱?

我在哪里使用工具箱?
EN

Stack Overflow用户
提问于 2019-06-17 14:59:43
回答 2查看 104关注 0票数 3

我正在研究一个科学应用程序,现在已经有十多个人在开发了。

最近,我们发现我们的应用程序需要多个工具箱,这些工具箱不是默认MATLAB安装的一部分。由于我们使用的是大学许可证,所以我们可以访问所有的工具箱,因此到目前为止我们从未注意到这一点。但是,我们希望将工具箱的数量减少到最低限度,以使其他组使用我们的软件更容易、更便宜。

当我跑的时候

代码语言:javascript
复制
[fList,pList] = matlab.codetools.requiredFilesAndProducts('myFile.m')

pList列出了几个工具箱,如:

代码语言:javascript
复制
 NAME                                  Version  id  Certain
'MATLAB'                                 '9.4'  1   true
'Robust Control Toolbox'               '6.4.1'  5   true
'Mapping Toolbox'                        '4.6'  11  true
'Financial Toolbox'                     '5.11'  30  true
'Aerospace Toolbox'                     '2.21'  108 true
'Parallel Computing Toolbox'            '6.12'  80  false
'MATLAB Distributed Computing Server'   '6.12'  94  false

我确信至少“Finacial Toolbox”和“Aerospace”并不是真正需要的,我们只通过将在线解决方案复制粘贴到我们的软件中来使用它。

例如,我们使用一个名为degrees2dms的函数,它是工具箱的一部分,简单地将十进制转换为度、分钟和秒。这可以很容易地由我们自己实现,而无需使用额外的工具箱。

我现在的问题是:

我知道从matlab.codetools.requiredFilesAndProducts中使用了哪些工具箱。如何从这些工具箱中找出哪些函数用于用我们自己的代码替换这些函数。

EN

回答 2

Stack Overflow用户

回答已采纳

发布于 2019-06-17 15:10:20

查看fList输出:这是运行myFile.m所需的自己的MATLAB程序文件列表。循环遍历它们,并对每个文件运行matlab.codetools.requiredFilesAndProducts,以确定代码库中的每个文件都需要哪个产品/哪些产品。这将有助于缩小您要关注的文件范围。

您还可以尝试在代码上运行依赖性报告,这可能为您提供一个更好的接口,以探索哪个文件使用哪个工具箱(Es)。

票数 3
EN

Stack Overflow用户

发布于 2019-06-17 15:53:05

这不是完全自动的semi-documented,它使用函数getcalliinfo,但可能会有所帮助。

来自help getcallinfo

代码语言:javascript
复制
GETCALLINFO  Returns called functions and their first and last lines
    This function is unsupported and might change or be removed without
    notice in a future version.

考虑一下这个示例函数,它使用了几个工具箱并包含一个本地函数:

代码语言:javascript
复制
function y = example(x)
a = sinc(2);
b = example_local_function(pi);
c = @xcorr;
d = c([1 2 3], [4 5 6]);
y = imdilate(x,[1 1; 1 1]);
end

function z = example_local_fun(t)
z = t.^2 + exprnd(1);
end

将此函数保存到文件example.m并运行getcallinfo

代码语言:javascript
复制
>> getcallinfo('example.m')
Name                 Type                 Starts Ends Length Full Name           
----                 ----                 ------ ---- ------ ---------           
example              function                1     7      7 example             
example_local_fun    subfunction             9    11      3 example>example_local_fun
ans = 
  1×2 struct array with fields:
    type
    name
    fullname
    functionPrefix
    calls
    firstline
    lastline
    linemask

结果是一个包含两个条目的struct数组:第一个用于主函数,第二个用于本地函数。观察第一项:

代码语言:javascript
复制
>> t(1)
ans = 
  struct with fields:

              type: [1×1 internal.matlab.codetools.reports.matlabType.Function]
              name: 'example'
          fullname: 'example'
    functionPrefix: 'example>'
             calls: [1×1 struct]
         firstline: 1
          lastline: 7
          linemask: [11×1 logical]

被调用的函数在

代码语言:javascript
复制
>> t(1).calls
ans = 
  struct with fields:

      fcnCalls: [1×1 struct]
    innerCalls: [1×1 struct]
      dotCalls: [1×1 struct]
       atCalls: [1×1 struct]

具体来说,在这种情况下,仅有的两个非空结构是

代码语言:javascript
复制
>> t(1).calls.fcnCalls
ans = 
  struct with fields:    
    names: {'sinc'  'example_local_function'  'pi'  'imdilate'}
    lines: [2 3 3 6]

>> t(1).calls.atCalls
ans = 
  struct with fields:    
    names: {'xcorr'}
    lines: 4

要查看被调用函数的定义位置,可以将which应用于包含在字段names中的单元格数组中的每个单元格。

代码语言:javascript
复制
C:\Program Files\MATLAB\R2018b\toolbox\signal\signal\sinc.m
'example_local_function' not found.
built-in (C:\Program Files\MATLAB\R2018b\toolbox\matlab\elmat\pi)
C:\Program Files\MATLAB\R2018b\toolbox\images\images\imdilate.m

要自动化这个过程,您需要知道工具箱文件夹的名称(这很容易从您的Matlab安装中看到)。例如,用于图像处理工具箱的是'images' (或者您可能更喜欢使用完整的路径来避免误报):

代码语言:javascript
复制
>> s = cellfun(@which, t(1).calls.fcnCalls.names, 'UniformOutput', false);
>> ind = ~cellfun(@isempty, regexp(s, 'images', 'once'));
>> t(1).calls.fcnCalls.names(ind)
>> t(1).calls.fcnCalls.names(ind)
ans =
  1×1 cell array
    {'imdilate'}

对于其他工具箱,该过程是相同的。例如,信号处理工具箱的文件夹称为'signals'

代码语言:javascript
复制
>> s = cellfun(@which, t(1).calls.fcnCalls.names, 'UniformOutput', false);
>> ind = ~cellfun(@isempty, regexp(s, 'signal', 'once'));
>> t(1).calls.fcnCalls.names(ind)
ans =
  1×1 cell array
    {'sinc'}

同样,对于其他类型的呼叫:

代码语言:javascript
复制
>> s = cellfun(@which, t(1).calls.atCalls.names, 'UniformOutput', false);
>> ind = ~cellfun(@isempty, regexp(s, 'signal', 'once'));
>> t(1).calls.atCalls.names(ind)
ans =
  1×1 cell array
    {'xcorr'}

或局部功能:

代码语言:javascript
复制
>> s = cellfun(@which, t(2).calls.fcnCalls.names, 'UniformOutput', false)
>> ind = ~cellfun(@isempty, regexp(s, 'stats', 'once'));
>> t(2).calls.fcnCalls.names(ind)
ans =
  1×1 cell array
    {'exprnd'}
票数 2
EN
页面原文内容由Stack Overflow提供。腾讯云小微IT领域专用引擎提供翻译支持
原文链接:

https://stackoverflow.com/questions/56633944

复制
相关文章

相似问题

领券
问题归档专栏文章快讯文章归档关键词归档开发者手册归档开发者手册 Section 归档