%
% Function to plot a Residuals distribution
% together with an equivalent Normal distribution
%
% Bob Newell, February 1996
%
function h = resdist( resid )
% histogram of residuals
h = figure;
hist( resid, 20 );
hold on;
% determine the x axis range
b = max( resid );
a = min( resid );
r = max( [ b -a ] );
x = -r:(b-a)/100:r;
% generate a Normal distribution
v = cov( resid );
y = exp( - x .* x / 2 / v ) / sqrt( 2 * pi * v );
% scale it in the y direction
y = y * length( resid ) * ( b - a ) / 20;
% plot over histogram
plot( x, y );
hold off;
% that's all
return;