checking a matlab function for nested functions

8 ビュー (過去 30 日間)
Alain Barraud
Alain Barraud 2019 年 10 月 5 日
コメント済み: Image Analyst 2019 年 10 月 12 日
how to find programatically if a matlab function m file contains nested function.
fileData = mlintmex('-calls',which(fileName));
fileData = regexp(fileData,'[NS](\d+) (\d+) \d+ (\w+)\n','tokens');
gives the list of function within fileName. My question is how to distinguish local functions from nested functions?
Best regards
  7 件のコメント
Alain Barraud
Alain Barraud 2019 年 10 月 10 日
I have found the answer to my question. The undocumented function mtree contains all the necessary infos. The only difficulty is to find where to search. The wrapper getcallinfo, another undocumented function gives a good approach to retrieve what I am asking for, once all the nested struct fields have been visited.
Alain
Image Analyst
Image Analyst 2019 年 10 月 12 日
You could easily find all function definitions by opening the m-file as a text file, using fgetl() to get a line, then using contains() or startsWith() to see if the line contains a function definition
fid = fopen(mFileName, 'rt');
textLine = fgetl(fid);
while ischar(textLine)
if startsWith(strtrim(textLine), 'function ')
% It's a function definition...
end
textLine = fgetl(fid); % Read next line
end
fclose(fid);

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

回答 (1 件)

Image Analyst
Image Analyst 2019 年 10 月 8 日
See the attached function to list all the dependent m-files.
  1 件のコメント
Alain Barraud
Alain Barraud 2019 年 10 月 9 日
I use directly matlab.codetools.requiredFilesAndProducts(). However the local functions don't appear, only the main function whose name is attached to file name.

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

カテゴリ

Help Center および File ExchangeFile Compression についてさらに検索

Community Treasure Hunt

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

Start Hunting!

Translated by