%% pwerr.m is my version of errorbar. It has the advantage
%% that it can be combined with other plot commands,
%% which errorbar does not seem to be able to do. It 
%% uses the same upper and lower bounds for the error
%% range.
%%

function pwerr(x,y,ye,cv)

% x = x-values
% y = y-values
% ye = error in y-values
% cv = valid string to give plot colour

%convert all input to column vectors
x=x(:);
y=y(:);
ye=ye(:);

%remove terms with 0 error
yec=ye==0;
if any(yec)
 x(yec)=[];
 y(yec)=[];
 ye(yec)=[];
end 

yu=y+ye;                                        %upper error values
yl=y-ye;                                        %lower error values

xmx=max(x)-min(x);                              %seperation in x values
xu=x+0.01*xmx;                                  %upper x values for errorbar tops
xl=x-0.01*xmx;                                  %lower x values for errorbar tops

h1=plot([x x]',[yu yl]',cv,[xl xu]',[yl yl]',cv,[xl xu]',[yu yu]',cv);
set(h1,'linewidth',2)
