function d=calcerr(a,b)
%CALCERR Calculates matrix or cell array errors.
%
%	D = CALCERR(A,B)
%	  A - MxN matrix.
%	  B - MxN matrix.
%	Returns
%	  D - MxN matrix A-B.
%
%	D = CALCERR(A,B)
%	  A - MxN cell array of matrices A{i,j}.
%	  B - MxN cell array of matrices B{i,j}.
%	Returns
%	  D - MxN cell array of matrices A{i,j}-B{i,j}.

% Mark Beale, 11-31-97
% Copyright (c) 1992-1998 by The MathWorks, Inc.
% $Revision: 1.3 $

if isa(a,'double') & isa(b,'double')

  d = a-b;

elseif isa(a,'cell') & isa(b,'cell')

  [m,n] = size(a);
  d = cell(m,n);
  for i=1:m
    for j=1:n
      d{i,j} = a{i,j}-b{i,j};
    end
  end

else

  error('Inputs must both be matrices or both be cell-arrays')

end
