function maeresize(name, m, n)
%MAERESIZE Change the size of a matrix to be [m n].
%   For use by the Array Editor.
%   NAME is a char array naming a 2D numeric array in the caller's
%   workspace.  M is the new number of rows and N is the new number
%   of columns.
%   Example: if NAME is 'x', M = 2, N = 2, and x is a 1x1 array
%   in the caller's workspace with the value 3, then MAERESIZE will
%   change x to have the value [3 0; 0 0].
%
%   See also EDITARRAY.

%   Copyright (c) 1984-98 by The MathWorks, Inc.
%   $Revision: 1.6 $  $Date: 1998/05/28 19:51:14 $

if nargin < 3
    error('Too few input arguments.');
elseif nargin > 3
    error('Too many input arguments.');
end
if ~isstr(name)
    error('NAME must be a character array.');
end
if ~isnumeric(m) | ~isreal(m) | (prod(size(m) ~= 1)) |...
   ~isnumeric(n) | ~isreal(n) | (prod(size(n) ~= 1))
    error('M and N must be real scalars.');
end

% Verify that the named array exists (in the workspace from which this
% function was called) and that it is 2D numeric.  If not, then print
% an error code:
%    -1 => there is no such array in the workspace
%    -2 => the array is non-numeric
%    -3 => the array is not 2D
% The reason we print error codes rather than just calling "error" is
% that the error codes are for the benefit of the Array Editor, not
% the user.

% check to see whether the array whose name is in the "name" arg
% exists in the caller's workspace
if evalin('caller', ['exist(''' name ''') == 1'])
    % yes, get the array
    array = evalin('caller', name);
    if isnumeric(array)
        if ndims(array) == 2            % vectors and [] are OK too
            % now do some real work: resize the array as requested
            [mCur nCur] = size(array);  % current dims
            if(m > mCur)
                % increase the number of rows by zero-filling
                evalin('caller', sprintf('%s(%d:%d,:)=0', name, mCur+1, m));
            elseif m < mCur
                % decrease the number of rows by deleting
                evalin('caller', sprintf('%s(%d:%d,:)=[]', name, m+1, mCur));
            end
            if(n > nCur)
                % increase the number of columns by zero-filling
                evalin('caller', sprintf('%s(:,%d:%d)=0', name, nCur+1, n));
            elseif n < nCur
                % decrease the number of columns by deleting
                evalin('caller', sprintf('%s(:,%d:%d)=[]', name, n+1, nCur));
            end
        else
            disp(-3);     % the array is not 2D
        end
    else
        disp(-2);         % the array is not numeric
    end
else
    disp(-1);             % there is no such array in the workspace
end

