List Built in Commands used by .m function

조회 수: 4(최근 30일)
Scott
Scott 2015년 2월 24일
댓글: Scott 2015년 2월 24일
I'd like to analyse a set of .m functions that have been written to see which built-in commands have been used by the authors.
The results of this analysis will be to create a coding standard which specifies which built-in commands may be used and which are prohibited.
The "Dependency Report" shows me which functions I've used but not the built-in commands. Anyone know if this is possible?
Thanks.

채택된 답변

Guillaume
Guillaume 2015년 2월 24일
One possible way, use the undocumented mtree function to get the parse tree of the code, identify the function calls in that tree (the hard bit!), then use exist to identify the built in ones
For example (works on R2014b):
parsetree = mtree('array2table.m', '-file');
treeids = parsetree.mtfind('Kind', 'ID');
idstrings = unique(treeids.strings);
isbuiltin = cellfun(@(id) exist(id, 'builtin') == 5, idstrings);
nonbuiltinid = idstrings(~isbuiltin)
builtinid = idstrings(isbuiltin)
  댓글 수: 3
Scott
Scott 2015년 2월 24일
Thanks for your help. I've got something that will meet my needs.

댓글을 달려면 로그인하십시오.

추가 답변(0개)

범주

Find more on Startup and Shutdown in Help Center and File Exchange

Community Treasure Hunt

Find the treasures in MATLAB Central and discover how the community can help you!

Start Hunting!

Translated by