function [xo,yo] = bar(x,y)
%BAR	Bar graph.
%	BAR(Y) draws a bar graph of the elements of vector Y.
%	BAR(X,Y) draws a bar graph of the elements in vector Y at
%	the locations specified in X.  The X-values must be in
%	ascending order and evenly spaced.
%	[XX,YY] = BAR(X,Y) does not draw a graph, but returns vectors
%	X and Y such that PLOT(XX,YY) is the bar chart.
%	See also STAIRS and HIST.

%	C.B Moler 2-06-86
%	Modified 24-Dec-88, LS.
%	Copyright (c) 1985-88 by the MathWorks, Inc.
               
n = length(x);
if nargin == 1
	y = x;
	x = 1:n;
end
delta = (max(x) - min(x)) / (n-1);
nn = 3*n;
yy = zeros(nn+1,1);
xx = yy;
t = x(:)' - 0.5*delta;
xx(1:3:nn) = t;
xx(2:3:nn) = t;
xx(3:3:nn) = t + delta;
yy(2:3:nn) = y;
yy(3:3:nn) = y;
xx(nn+1) = xx(nn);
if nargout == 0
	plot(xx,yy,[xx(1) xx(length(xx))],[0 0],'-')
else
	xo = xx;
	yo = yy;
end
