No BSD License  

image thumbnail

Get function's help infomation saved into a single file

by

 

13 Nov 2007 (Updated )

Saves the help information of functions into a single file. This is sometimes useful when exploring

GetFunInfo(OutFile,Functions)
function GetFunInfo(OutFile,Functions)
% Save the help information in function files into a single file.
%
% GetFunInfo(OutFile) saves the help information in function files under
% the current directory into OutFile. This file will be created if haven't
% done so and will be overwritten if exists.
%
% GetFunInfo(OutFile,Functions) saves the help information in functions 
% specified in Functions into OutFile. Functions is a cell array and each element
% of the it is one function name.
%
% Example:
%           >> GetFunInfo('FunctionInfo.txt');
%               Saves function information into FunctionInfo.txt
%
%           >> f = {'abs','sign'};
%           >> GetFunInfo('FunctionInfo.txt',f)
%               Saves information of functions abs and sign into
%               FunctionInfo.txt
%
%
% Note that the output file is easier to read using wordpad than notepad 
% under windows. Notepad tends to have word wrapping problem when displaying
% the text.
%
%
%
%
% Bo Qiang, qiangbo@gmail.com, 11/13/07



if(nargin < 1)
    error('At least output file name is needed.');
elseif(nargin > 2)
    error('Too many input arguments.');
end

fid = fopen(OutFile,'w');
if (fid<0)
    error('Failed to have access or create the output file.')
end

if(nargin == 1)
    list = dir('*.m');
    Functions = {list.name}';
end
for m = 1:length(Functions)
    h = help(Functions{m});
    fwrite(fid,'-----------------------------------');
    fwrite(fid,Functions{m});
    fwrite(fid,'-----------------------------------');
    fprintf(fid,'\n');
    if isempty(h)
        fwrite(fid,'No description found.');
        fprintf(fid,'\n');
    else
        fwrite(fid,h);
    end
end

fclose(fid);

Contact us