我正在研究一个科学应用程序,现在已经有十多个人在开发了。
最近,我们发现我们的应用程序需要多个工具箱,这些工具箱不是默认MATLAB安装的一部分。由于我们使用的是大学许可证,所以我们可以访问所有的工具箱,因此到目前为止我们从未注意到这一点。但是,我们希望将工具箱的数量减少到最低限度,以使其他组使用我们的软件更容易、更便宜。
当我跑的时候
[fList,pList] = matlab.codetools.requiredFilesAndProducts('myFile.m')pList列出了几个工具箱,如:
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中使用了哪些工具箱。如何从这些工具箱中找出哪些函数用于用我们自己的代码替换这些函数。
发布于 2019-06-17 15:10:20
查看fList输出:这是运行myFile.m所需的自己的MATLAB程序文件列表。循环遍历它们,并对每个文件运行matlab.codetools.requiredFilesAndProducts,以确定代码库中的每个文件都需要哪个产品/哪些产品。这将有助于缩小您要关注的文件范围。
您还可以尝试在代码上运行依赖性报告,这可能为您提供一个更好的接口,以探索哪个文件使用哪个工具箱(Es)。
发布于 2019-06-17 15:53:05
这不是完全自动的semi-documented,它使用函数getcalliinfo,但可能会有所帮助。
来自help getcallinfo
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.考虑一下这个示例函数,它使用了几个工具箱并包含一个本地函数:
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
>> 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数组:第一个用于主函数,第二个用于本地函数。观察第一项:
>> 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]被调用的函数在
>> t(1).calls
ans =
struct with fields:
fcnCalls: [1×1 struct]
innerCalls: [1×1 struct]
dotCalls: [1×1 struct]
atCalls: [1×1 struct]具体来说,在这种情况下,仅有的两个非空结构是
>> 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中的单元格数组中的每个单元格。
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' (或者您可能更喜欢使用完整的路径来避免误报):
>> 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'
>> 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'}同样,对于其他类型的呼叫:
>> 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'}或局部功能:
>> 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'}https://stackoverflow.com/questions/56633944
复制相似问题