Code covered by the BSD License  

Highlights from
Generate help files from m-files

image thumbnail
from Generate help files from m-files by Wolfgang Garn
Help files are generated from m-files.

wg_publish_dir(directory, destination_format, destination_directory)
function wg_publish_dir(directory, destination_format, destination_directory)
% WG_PUBLISH_DIR Creates help files for all m-files within a directory.
% Reads the comments in a m-function or m-script. It marks them up and extends them
% whenever necessary. It automatically creates the syntax and several 
% headings. It also executes commented(%+) examples and even includes the
% graphics. 
% How it works ...
% First the m-function is converted into a Matlab script. Then Matlab's
% pulish function is executed.
% In case the destination format is html, the 'see also' functions are 
% enabled.
% 
% Input:
% * directory ... the directory containing the m-functions and m-scripts
% for which you like to create the help
% * (optional) destination_format ... 'doc','html' (default), 'latex', 'ppt', 'xml' 
% * (optional) destination_directory ... directory for the publish or html folder. 
%
% Output:
% * scripts and help files
%
% Example
% Creates help files for any directory. All m-files are read and correpsonding
% html files in the html subdirectory are created.
%   |wg_publish_dir|
%
% Create help files of the current directory.
% |wg_publish_dir( pwd );|
%
% Generate documentation for a directory as Word documentation in the
% subfolder 'doc'.
% |wg_publish_dir( 'C:\MATLAB704\work\Common\plot','doc');|
%
% Publish the help files as latex documentation in a specified folder.
% |wg_publish_dir( pwd,'latex','C:\latex');|

% See also: publish, wg_publish, wg_publish_all, create_index_html
%
%% Signature
% Author: W.Garn
% E-Mail: wgarn@yahoo.com
% Date: 2005/12/01 20:00:00 
% 
% Copyright 2005 W.Garn
%
if nargin<1
    directory = uigetdir(pwd,'Select directory with m-functions'); % cancle not caught
end
if nargin<2
    destination_format = 'html';
end
if nargin<3
    destination_directory=[directory '\' destination_format];
end
if ischar(directory) 
    if exist(directory,'dir')
        current_dir = pwd;
        cd(directory);
        files = dir(fullfile(directory, '*.m'));
        fid=1;
        fprintf(fid,'----------------------------------\n',length(files));
        fprintf(fid,'Started processing of %i files ...\n',length(files));
        %progressbar(0,[0.2 0.7]);
        bytes = filesBytes(files);     progressed_bytes=0;

        fprintf(fid,'A total of %.0f kilo bytes.\n',bytes/1024);
        for k=1:length(files)
            fprintf(1,[files(k).name '\n']);
            wg_publish(files(k).name,destination_format,destination_directory);
            progressed_bytes = progressed_bytes + files(k).bytes;
            %progressbar(progressed_bytes/bytes);
            fprintf(fid,'\nProgress: %.1f%% \n',progressed_bytes/bytes*100);
            fprintf(fid,'A total of %.0f kilo bytes processed.\n\n',progressed_bytes/1024);
        end

        %progressbar(1);
        fprintf(fid,'Finished creating documentation.\n');
        fprintf(fid,'--------------------------------\n');
        cd(current_dir); % restore directory
    end
end

function bytes = filesBytes(files)
bytes=0;
for k=1:length(files)
    bytes = bytes + files(k).bytes;
end

Contact us at files@mathworks.com