function out = openmat(filename)
%OPENMAT   Load data from file and show preview.
%   Helper function for OPEN.
%
%   See OPEN.

%   Copyright 1984-2000 The MathWorks, Inc.
%   $Revision: 1.8 $  $Date: 2000/06/01 01:25:39 $

try
   out = load(filename); 
catch
    % we only want the message from lasterr, not the stack trace
    le = lasterr;
    euIndex = findstr(le, 'Error using');
    if ~isempty(euIndex)
        le = le(euIndex(end):end);
        nlIndex = findstr(le,sprintf('\n'));
        if ~isempty(nlIndex)
            le = le(nlIndex(1) + 1 : end);
            while ~isempty(le) & length(le) > 1 & strcmp(le(end), sprintf('\n'))
                le = le(1:end - 1);
            end
        end
    end
    error(le)
end
    
