function  s = mat2str1(M,format)

%MAT2STR1 -- Compact string representation of an array of dim<=2.
%
%  S = MAT2STR1(M)  converts the array M into a sting representation S.
%  It branches of to NUM2STR, VECT2STR, or MAT2STR depending on the
%  shape of M.
%
%  S = VECT2STR(M,FORMAT) uses the format string FORMAT (see SPRINTF).
%
%  Examples:
%    mat2str1(pi)         ==>  '3.1416'
%    mat2str1([1:0.5:3]') ==>  '[1 1.5 2 2.5 3 ]''
%    mat2str1(magic(3))   ==>  'reshape([8 3 4 1 5 9 6 7 2 ],[3 3 ])'
%    mat2str1([])         ==>  '[]'
%
%  Deprecation note: This function is redundant in many Matlab versions
%    because the standard mat2str handles scalars and vectors quite nicely.
%
%  See also MAT2STR, VECT2STR, NUM2STR, INT2STR, SPRINTF, SSCANF, EVAL.

% Original coding by Alex Petrov, Ohio State University
% $Revision: 1.0 $  $Date: 2004/03/03 10:30 $
%
% Part of the utils toolbox version 1.1 for MATLAB version 5 and up.
% http://alexpetrov.com/softw/utils/
% Copyright (c) Alexander Petrov 1999-2006, http://alexpetrov.com
% Please read the LICENSE and NO WARRANTY statement in ../utils_license.m

[r,c] = size(M) ;

if (nargin==1)
   if (r==1 & c==1)    s = num2str(M) ;     % scalar
   elseif (r>1 & c>1)  s = mat2str(M) ;     % full matrix
   else                s = vect2str(M) ;    % vector, []
   end
else
   if (r==1 & c==1)    s = num2str(M,format) ;
   elseif (r>1 & c>1)  s = mat2str(M,format) ;
   else                s = vect2str(M,format) ;
   end
end

%--- Return s
%%%%% End of file MAT2STR1.M