function normqqplot(x,hlim,llim);
% NORMQQPLOT - plot quantiles of data vs quantiles of normal distribution
%
%   normqqplot - plot quantiles of data vs quantiles of normal distribution
%  normqqplot(x)
%  does no labelling
%         See also QQPLOT

% Copyright (c) 1998 by Datatool
% Revision: 1.00

% This function comes from http://datatool.com/ and appears to have been 
% modified and separated from the rest of the datatool dvt toolbox without 
% comment.
% VERSION:
%	$Revision: 1.6 $
%	$Date: 2008/01/19 19:58:02 $
%	$Id: normqqplot.m,v 1.6 2008/01/19 19:58:02 duncombe Exp duncombe $

x = sort(x);
n = length(x);
%  calculate fractional scale for this number of quantiles
f = ((1:n)-0.5)/n;
%  get  normal distribution quantiles
normalQ = sqrt(2)*erfinv(2*f-1);
%  calculate quartile - quartile line
q1 = round(n/4);
q2 = round(3*n/4);
slope = (x(q2)-x(q1))/(normalQ(q2)-normalQ(q1));
intercept = x(q1)-slope*normalQ(q1);
y = slope*[normalQ(1) normalQ(n)]+intercept;
%  make plot
plot(normalQ,x,'o',[normalQ(1) normalQ(n)],y,'r--')
hold on
aux=find(x<=llim | x>=hlim);
plot(normalQ(aux),x(aux),'ro',[normalQ(1) normalQ(n)],y,'r--')

