Home > utility > funcExtract.m

funcExtract

PURPOSE ^

funcExtract: Extract possible function names from a given M file

SYNOPSIS ^

function funcName=funcExtract(fileName)

DESCRIPTION ^

 funcExtract: Extract possible function names from a given M file
    Usage: funcName=funcExtract(fileName)

CROSS-REFERENCE INFORMATION ^

This function calls: This function is called by:

SUBFUNCTIONS ^

SOURCE CODE ^

0001 function funcName=funcExtract(fileName)
0002 % funcExtract: Extract possible function names from a given M file
0003 %    Usage: funcName=funcExtract(fileName)
0004 
0005 %    Roger Jang, 20080913
0006 
0007 if nargin<1, selfdemo; return; end
0008 
0009 contents = textread(fileName,'%s','delimiter','\n','whitespace','');
0010 pat='\s*(\w+?)\(';
0011 
0012 funcName={};
0013 for i=1:length(contents)
0014     line=contents{i};
0015     tokens = regexp(line, pat, 'tokens');
0016     for j=1:length(tokens);
0017         for k=1:length(tokens{j})
0018             funcName{end+1}=tokens{j}{k};
0019         end
0020     end
0021 end
0022 funcName=unique(funcName);
0023 
0024 % ====== Self demo
0025 function selfdemo
0026 fileName=mfilename;
0027 funcName=funcExtract(fileName)

Generated on Tue 01-Jun-2010 09:50:34 by m2html © 2003