www.gusucode.com > rptgen 工具箱matlab源码程序 > rptgen/rptviewfile.m

    function varargout = rptviewfile(varargin)
%RPTVIEWFILE launches a viewer for input files
%   RPTVIEWFILE <FILENAME.EXT> launches a viewer for the file.  Multiple
%   file names may be passed in.  Use the functional form of the
%   command RPTVIEWFILE('FILENAME') if the name contains spaces.
%
%   OK=RPTVIEWFILE('FILENAME1.EXT','FILENAME2.EXT') will return a
%   logical vector showing whether the file was launched properly
%   or not.
%
%   [OK,MSG]=RPTVIEWFILE('FILENAME1.EXT','FILENAME2.EXT') will
%   return a logical array and a cell array containing error
%   messages.  Errors will not be displayed to the screen and will
%   not halt execution of the function.

%   Viewer launch commands are defined in RPTPARENT/PREFERENCES
%   and can be edited by the user.
%
%   See also RPTPARENT/PREFERENCES.

%   Copyright 1997-2012 The MathWorks, Inc.

%if nargout==2, errors/warnings/messages are saved to a string and not
%written to screen.
dispErrors = (nargout<2);

ok = false(1,nargin);
for i = 1:nargin

        try
            rptgen.viewFile(varargin{i});
            ok(i) = true;
            statusString = '';
        catch ME
            statusString = ME.message;
            ok(i) = false;
        end

    
    %if we are not outputting status messages and the viewer was
    %not launched successfully, throw an error.  Otherwise, put the error
    %message into the errMsg cell array
    if dispErrors
        if ~ok(i)
            error(message('rptgen:rptgenrptgen:viewFileErrorMsg', statusString));
        end
    else
        errMsg{i} = statusString; %#ok
    end

end

if nargout>0
    varargout{1} = ok;
    if ~dispErrors %dispErrors happens when varargou==2
        varargout{2} = errMsg;
    end
end