Home > matutils > errorbar_x.m

errorbar_x

PURPOSE ^

ERRORBAR Error bar plot.

SYNOPSIS ^

function hh = errorbar_x(x, y, l,u,symbol)

DESCRIPTION ^

ERRORBAR Error bar plot.
   ERRORBAR_X(X,Y,L,U) plots the graph of vector X vs. vector Y with 
   error bars specified by the vectors L and U in horizontal direction.  
   L and U contain the lower and upper error ranges for each point 
   in X (lower = left side, upper = right side).  Each error bar is 
   L(i) + U(i) long and is drawn a distance of U(i) from the right 
   and L(i) from the left the points in (X,Y).  The vectors X,Y,L 
   and U must all be the same length.  If X,Y,L and U are matrices 
   then each column produces a separate line.

   ERRORBAR_X(X,Y,E) or ERRORBAR(Y,E) plots X with error bars [X-E X+E].
   ERRORBAR_X(...,'LineSpec') uses the color and linestyle specified by
   the string 'LineSpec'.  See PLOT for possibilities.

   H = ERRORBAR_X(...) returns a vector of line handles.

   For example,
      x = 1:10;
      y = sin(x);
      e = std(y)*ones(size(x));
      errorbar_x(x,y,e)
   draws symmetric error bars of unit standard deviation.

CROSS-REFERENCE INFORMATION ^

This function calls: This function is called by:

SOURCE CODE ^

0001 function hh = errorbar_x(x, y, l,u,symbol)
0002 %ERRORBAR Error bar plot.
0003 %   ERRORBAR_X(X,Y,L,U) plots the graph of vector X vs. vector Y with
0004 %   error bars specified by the vectors L and U in horizontal direction.
0005 %   L and U contain the lower and upper error ranges for each point
0006 %   in X (lower = left side, upper = right side).  Each error bar is
0007 %   L(i) + U(i) long and is drawn a distance of U(i) from the right
0008 %   and L(i) from the left the points in (X,Y).  The vectors X,Y,L
0009 %   and U must all be the same length.  If X,Y,L and U are matrices
0010 %   then each column produces a separate line.
0011 %
0012 %   ERRORBAR_X(X,Y,E) or ERRORBAR(Y,E) plots X with error bars [X-E X+E].
0013 %   ERRORBAR_X(...,'LineSpec') uses the color and linestyle specified by
0014 %   the string 'LineSpec'.  See PLOT for possibilities.
0015 %
0016 %   H = ERRORBAR_X(...) returns a vector of line handles.
0017 %
0018 %   For example,
0019 %      x = 1:10;
0020 %      y = sin(x);
0021 %      e = std(y)*ones(size(x));
0022 %      errorbar_x(x,y,e)
0023 %   draws symmetric error bars of unit standard deviation.
0024 
0025 %   L. Shure 5-17-88, 10-1-91 B.A. Jones 4-5-93
0026 %   Copyright 1984-2002 The MathWorks, Inc.
0027 %   $Revision: 1.1 $  $Date: 2010/02/08 23:21:58 $
0028 
0029 %   modified for plotting error bars in a logarithmic graph by:
0030 %   Goetz Huesken
0031 %   e-mail: goetz.huesken(at)gmx.de
0032 %   Date: 10/23/2006
0033 
0034 
0035 if min(size(x))==1,
0036   npt = length(x);
0037   x = x(:);
0038   y = y(:);
0039     if nargin > 2,
0040         if ~isstr(l),  
0041             l = l(:);
0042         end
0043         if nargin > 3
0044             if ~isstr(u)
0045                 u = u(:);
0046             end
0047         end
0048     end
0049 else
0050   [npt,n] = size(x);
0051 end
0052 
0053 if nargin == 3
0054     if ~isstr(l)  
0055         u = l;
0056         symbol = '-';
0057     else
0058         symbol = l;
0059         l = y;
0060         u = y;
0061         y = x;
0062         [m,n] = size(y);
0063         x(:) = (1:npt)'*ones(1,n);;
0064     end
0065 end
0066 
0067 if nargin == 4
0068     if isstr(u),    
0069         symbol = u;
0070         u = l;
0071     else
0072         symbol = '-';
0073     end
0074 end
0075 
0076 
0077 if nargin == 2
0078     l = y;
0079     u = y;
0080     y = x;
0081     [m,n] = size(y);
0082     x(:) = (1:npt)'*ones(1,n);;
0083     symbol = '-';
0084 end
0085 
0086 u = abs(u);
0087 l = abs(l);
0088     
0089 if isstr(x) | isstr(y) | isstr(u) | isstr(l)
0090     error('Arguments must be numeric.')
0091 end
0092 
0093 if ~isequal(size(x),size(y)) | ~isequal(size(x),size(l)) | ~isequal(size(x),size(u)),
0094   error('The sizes of X, Y, L and U must be the same.');
0095 end
0096 
0097 m = size(y,1);                      % modification for plotting error bars in x-direction
0098 if m == 1                           %
0099   tee = abs(y)/40;                  %
0100 else                                %
0101   tee = (max(y(:))-min(y(:)))/40;   %
0102 end                                 %
0103                                     %
0104 xl = x - l;                         %
0105 xr = x + u;                         %
0106 ytop = y + tee;                     %
0107 ybot = y - tee;                     %
0108 n = size(y,2); 
0109 
0110 % Plot graph and bars
0111 hold_state = ishold;
0112 cax = newplot;
0113 next = lower(get(cax,'NextPlot'));
0114 
0115 % build up nan-separated vector for bars
0116 xb = zeros(npt*9,n);    % modification for plotting error bars in in x-direction
0117 xb(1:9:end,:) = xr;     %
0118 xb(2:9:end,:) = xl;     %
0119 xb(3:9:end,:) = NaN;    %
0120 xb(4:9:end,:) = xr;     %
0121 xb(5:9:end,:) = xr;     %
0122 xb(6:9:end,:) = NaN;    %
0123 xb(7:9:end,:) = xl;     %
0124 xb(8:9:end,:) = xl;     %
0125 xb(9:9:end,:) = NaN;    %
0126 
0127 yb = zeros(npt*9,n);    % modification for plotting error bars in in x-direction
0128 yb(1:9:end,:) = y;      %
0129 yb(2:9:end,:) = y;      %
0130 yb(3:9:end,:) = NaN;    %
0131 yb(4:9:end,:) = ytop;   %
0132 yb(5:9:end,:) = ybot;   %
0133 yb(6:9:end,:) = NaN;    %
0134 yb(7:9:end,:) = ytop;   %
0135 yb(8:9:end,:) = ybot;   %
0136 yb(9:9:end,:) = NaN;    %
0137 
0138 [ls,col,mark,msg] = colstyle(symbol); if ~isempty(msg), error(msg); end
0139 symbol = [ls mark col]; % Use marker only on data part
0140 esymbol = ['-' col]; % Make sure bars are solid
0141 
0142 h = plot(xb,yb,esymbol); hold on
0143 h = [h;plot(x,y,symbol)]; 
0144 
0145 if ~hold_state, hold off; end
0146 
0147 if nargout>0, hh = h; end

Generated on Sun 14-Jun-2015 17:12:45 by m2html © 2005