Reading the required variables for a function
이전 댓글 표시
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
Azzi Abdelmalek
2013년 11월 5일
Do you want the number of variables or their names?
Adam
2013년 11월 5일
답변 (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
Adam
2013년 11월 5일
Azzi Abdelmalek
2013년 11월 5일
편집: Azzi Abdelmalek
2013년 11월 5일
the test while isempty(line) checks if the first lines are empty
Walter Roberson
2013년 11월 5일
편집: Walter Roberson
2013년 11월 5일
Remember comment lines, and comments more generally.
Watch out for continuation lines.
Azzi Abdelmalek
2013년 11월 5일
For comment we can add a test
if line(1)=='%'
line=''
end
Walter Roberson
2013년 11월 5일
Comments can start anywhere on a line. Also, blanks are permitted on lines.
line = regexprep(line, {'%.*', '^s+'}, {'', ''});
Azzi Abdelmalek
2013년 11월 5일
The first character of line is always different from ' '
Image Analyst
2013년 11월 5일
0 개 추천
Maybe take a look at this: http://www.mathworks.com/matlabcentral/fileexchange/17291-fdep-a-pedestrian-function-dependencies-finder
카테고리
도움말 센터 및 File Exchange에서 Variables에 대해 자세히 알아보기
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!