%  err = mserr(x, y, dim)

%

%    Calculate mean square error of two vectors

%

%    Input:   x, y   =  two input vectors / matrices

%             dim    =  the dimension to calculate MSE along (optional, default = 1)

%    Output:  err    =  the mean square error of the input (average of squares of 

%                       differences along the specified dimension)



function  err = mserr(x, y, dim)



% check arguments

if ((nargin < 2) | (nargin > 3))

   error('mserr: invalid number of arguments');

end



% if dimension not supplied, set it to 1

if (nargin == 2)

   dim = 1;

end



% return the mean of squares of errors (difference between input vectors)

err = mean(((x - y) .^ 2), dim);

