function h = pareto(y,names)
%PARETO Pareto chart.
%   PARETO(Y,NAMES) produces a Pareto chart where the values in the
%   vector Y are drawn as bars in descending order.  Each bar will
%   be labeled with the associated name in the string matrix NAMES.
%   PARETO(Y) labels each element of Y with its index.
%
%   H = PARETO returns a combination of patch and line object handles.
%
%   See also HIST, BAR.

%   Copyright (c) 1993-96 by The MathWorks, Inc.
%   $Revision: 2.4 $  $Date: 1996/03/03 22:20:58 $

hold_state = ishold;
if nargin==1,
   names = '1'; 
   for k = 2:length(y);
       names = str2mat(names,num2str(k));
   end
end

if min(size(y))~=1, 
   error('Requires a vector first input argument.'); 
end
y = y(:);
[yy,ndx] = sort(y);
yy = flipud(yy); 
ndx = flipud(ndx);

bar(1:length(y),yy);
set(gca,'xtick',1:length(yy),'xticklabels',names(ndx,:))
hold on, 
hh = [hh;plot(cumsum(yy))];
k = min(find(cumsum(yy)/sum(yy)>.95));
set(gca,'xlim',[.5 k+.5])

if ~hold_state, hold off, end

if nargout>0, h = hh; end
