checking a matlab function for nested functions
Mostrar comentarios más antiguos
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 comentarios
Rik
el 5 de Oct. de 2019
I don't know how to best integrate this in your work flow, but the option you could resort to is to parse the function headers yourself, and checking where a new function starts before the previous function is closed with an end keyword.
Stephen23
el 6 de Oct. de 2019
"but the option you could resort to is to parse the function headers yourself, and checking where a new function starts..."
Probably not too difficult.
"...before the previous function is closed with an end keyword"
Considering comments, strings, operators, etc., that will not be trivial at all.
Perhaps mtree can help. Note that such meta-programming will be inherently slow and complex.
Alain Barraud
el 8 de Oct. de 2019
Steven Lord
el 8 de Oct. de 2019
I'm curious what you're planning to do with this information. Why do you need to perform this type of analysis?
Alain Barraud
el 8 de Oct. de 2019
Alain Barraud
el 10 de Oct. de 2019
Image Analyst
el 12 de Oct. de 2019
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);
Respuestas (1)
Image Analyst
el 8 de Oct. de 2019
0 votos
See the attached function to list all the dependent m-files.
1 comentario
Alain Barraud
el 9 de Oct. de 2019
Categorías
Más información sobre Scripts en Centro de ayuda y File Exchange.
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!