0001 function output = isFunction(filename);
0002
0003
0004
0005
0006 if nargin<1; selfdemo; return; end
0007
0008 fid=fopen(filename);
0009 line=fgetl(fid);
0010 fclose(fid);
0011
0012 start=regexp(line, '^function');
0013 output=0;
0014 if ~isempty(start)
0015 output=1;
0016 end
0017
0018
0019 function selfdemo
0020 fileName='isFunction.m';
0021 output=feval(mfilename, 'isFunction.m');
0022 if output
0023 fprintf('The given M-file "%s" is a function.', fileName);
0024 else
0025 fprintf('The given M-file "%s" is not a function.', fileName);
0026 end