home *** CD-ROM | disk | FTP | other *** search
- function errorbar(x, y, std)
- %ERRORBAR Plot graph with error bars.
- % ERRORBAR(X,Y,E) plots the graph of vector X vs. vector Y with
- % error bars specified by the vector E. The vectors X,Y and E must
- % be the same length. If X,Y, and E are matrices then each column
- % produces a separate line. The error bars are each drawn a distance
- % of E(i) above and below the points in (X,Y) so that each bar
- % is 2*E(i) long.
- %
- % ERRORBAR(Y,E) plots Y with error bars E.
- %
- % For example,
- %
- % x = 1:10;
- % y = sin(x);
- % e = std(y)*ones(size(x));
- % errorbar(x,y,e)
- %
- % draws error bars of unit standard deviation.
-
- % L. Shure 5-17-88, 10-1-91
- % Copyright (c) 1984-93 by The MathWorks, Inc.
-
- if min(size(x))==1,
- npt = length(x);
- x = x(:);
- y = y(:);
- if nargin>2, std = std(:); end
- else
- [npt,n] = size(x);
- end
-
- if nargin == 2
- std = y;
- y = x;
- [m,n] = size(y);
- x(:) = [1:npt]'*ones(1,n);;
- end
- if isstr(x) | isstr(y) | isstr(std)
- error('Arguments must be numeric.')
- end
-
- if any(size(x)~=size(y)) | any(size(x)~=size(std)),
- error('The sizes of X, Y, and E must be the same.');
- end
-
- tee = (max(x(:))-min(x(:)))/100; % make tee .02 x-distance for error bars
- xl = x - tee;
- xr = x + tee;
- n = size(y,2);
-
- % Plot graph and bars
- cax = newplot;
- next = lower(get(cax,'NextPlot'));
- % build up nan-separated vector for bars
- xb = [];
- yb = [];
- nnan = nan*ones(1,n);
- for i = 1:npt
- ytop = y(i,:) + std(i,:);
- ybot = y(i,:) - std(i,:);
- xb = [xb; x(i,:); x(i,:) ; nnan; xl(i,:);xr(i,:);nnan ;xl(i,:);xr(i,:);nnan];
- yb = [yb; ytop;ybot;nnan;ytop;ytop;nnan;ybot;ybot;nnan];
- end
-
- plot(xb,yb,x,y,'-')
-