Reading the required variables for a function
1 次查看(过去 30 天)
显示 更早的评论
Is there a function that will read the number and names of variables needed to run a function. I'm working on a brute force solution now that just opens the function as a text file and searches for the function declaration then reads the strings between the parenthesis.
2 个评论
回答(3 个)
Azzi Abdelmalek
2013-11-5
编辑:Azzi Abdelmalek
2013-11-5
fid = fopen('file.m');
line=''
while isempty(line)
line=fgetl(fid)
end
fclose(fid);
v=regexp(line,'(?<=\().+(?=\))','match')
n=strfind(v{1},',') % number of variables
%If you want their names
w=regexp(v{1},',','split')
6 个评论
Walter Roberson
2013-11-5
Comments can start anywhere on a line. Also, blanks are permitted on lines.
line = regexprep(line, {'%.*', '^s+'}, {'', ''});
Image Analyst
2013-11-5
Maybe take a look at this: http://www.mathworks.com/matlabcentral/fileexchange/17291-fdep-a-pedestrian-function-dependencies-finder
0 个评论
另请参阅
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!