说我有以下MATLAB函数do_this.m
function result = do_this(input1, input2)
% input1 and input2 must have the same size.
A = input1 + diag(input2);
result = rand(size(input1)) + A;
end
我想知道如何返回给定.m文件中使用的所有函数的数组。例如,
>> func_names = get_func_names('do_this.m')
func_names
为['diag', 'rand', 'size']
答案 0 :(得分:2)
您可以从depfun()
获取此类信息。
% See depfun helpfile
[TRACE_LIST, BUILTINS] = depfun('do_this.m');
BUILTINS
是函数所需的所有内置函数的单元格数组,并返回类似
BUILTINS =
'colon'
'datenummx'
'diag'
'evalin'
'horzcat'
'loadobj'
'numel'
'plus'
'rand'
'saveobj'
'size'
'subsindex'
'subsref'
'vertcat'
请注意,这也会返回diag()
,rand()
等使用的函数
在R2014a中(以及?),MATLAB警告Warning: DEPFUN will be removed in a future release. Use matlab.codetools.requiredFilesAndProducts instead.
但是,建议的函数不返回内置函数,只返回用户定义的函数。