List Built in Commands used by .m function

9 ビュー (過去 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 件のコメント
Guillaume
Guillaume 2015 年 2 月 24 日
Most likely, but you'll have to work it out for yourself. Have a look at the output of
parsetree.kinds
Once you've got the parse tree from mtree. Possibly, some other function / property of the tree can also be used. As I said, it's not documented and I know very little about it.
Also note that mtree is an experimental feature, so this may not work in future version. Saying that, it's been part of matlab for a while.
Scott
Scott 2015 年 2 月 24 日
Thanks for your help. I've got something that will meet my needs.

サインインしてコメントする。

その他の回答 (0 件)

カテゴリ

Help Center および File ExchangeIntroduction to Installation and Licensing についてさらに検索

製品

Community Treasure Hunt

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

Start Hunting!

Translated by