function y=zeropad(x,M,N)
% ZEROPAD  Pad an image with zeros to make it a desired size
%	
%	y=zeropad(x,N) pads the image x with zeros to make the output N-by-N
%	y=zeropad(x,M,N) pads the image x with zeros to make the output M-by-N
%	The function is also valid for text strings, in which the string is
%	padded with blanks.

if nargin<3,
  N=M;
end

[xM,xN]=size(x);

if xM>M | xN>N,
  error('Input is too large');
end

if isstr(x)
  y=blanks(N);
  y=y(ones(1,M),:);
  y(1:xM,1:xN)=x;
else
  y=[x zeros(xM,N-xN)
    zeros(M-xM,N)];
end