errobar_plus

PURPOSE ^

By Nguyen Chuong 2004/06/30

SYNOPSIS ^

function errobar_plus(x,y,e,prop,dir)

DESCRIPTION ^

 By Nguyen Chuong 2004/06/30
 This is to the problem of legend in errorbar
 This function put an errobar range onto plot
 Usage similar to errorbar():
   errobar_plus(x,y,e)
   errobar_plus(x,y,e,prop)
   errobar_plus(x,y,e,dir)
   errobar_plus(x,y,e,prop,dir)
   where prop is the property string like for plot()
   and dir is the vertical or horizontal direction of error
 For example,
        x = 1:10;
        y = sin(x);
        e = std(y)*ones(size(x));
        errorbar(x,y,e,'ri')
        figure
        errorbar(x,y,e,'r^')
     draws symmetric error bars of unit standard deviation.

CROSS-REFERENCE INFORMATION ^

This function calls: This function is called by:

SOURCE CODE ^

0001 function errobar_plus(x,y,e,prop,dir)
0002 % By Nguyen Chuong 2004/06/30
0003 % This is to the problem of legend in errorbar
0004 % This function put an errobar range onto plot
0005 % Usage similar to errorbar():
0006 %   errobar_plus(x,y,e)
0007 %   errobar_plus(x,y,e,prop)
0008 %   errobar_plus(x,y,e,dir)
0009 %   errobar_plus(x,y,e,prop,dir)
0010 %   where prop is the property string like for plot()
0011 %   and dir is the vertical or horizontal direction of error
0012 % For example,
0013 %        x = 1:10;
0014 %        y = sin(x);
0015 %        e = std(y)*ones(size(x));
0016 %        errorbar(x,y,e,'ri')
0017 %        figure
0018 %        errorbar(x,y,e,'r^')
0019 %     draws symmetric error bars of unit standard deviation.
0020 
0021 if exist('prop')
0022     color_list='bgrcmyk';
0023     mark_list='.ox+*sdv^<>ph';
0024     color='b';
0025     for j=1:numel(prop)
0026         for i=1:numel(color_list)
0027             if prop(j)==color_list(i)
0028                color=color_list(i);
0029                break
0030             end
0031         end
0032         if prop(j)==color_list(i)
0033            break
0034         end
0035     end
0036     mark='i';
0037     for j=1:numel(prop)
0038         for i=1:numel(mark_list)
0039             if prop(j)==mark_list(i)
0040                mark=mark_list(i);
0041                break
0042             end
0043         end
0044         if prop(j)==mark_list(i)
0045            break
0046         end
0047     end
0048 else
0049     color='b'; %default values
0050     mark='i';
0051 end
0052 if (exist('dir')==1) & (dir ~= 'v') & (dir ~= 'h')
0053     dir = 'v'; %default value
0054 elseif exist('dir')==5 % not exist
0055     dir = 'v'; %default value
0056 end
0057 dx=(x(1)-x(end))/numel(x)/12; % for the case mark='i' only
0058 dy=(y(1)-y(end))/numel(y)/12; % for the case mark='i' only
0059 hold on
0060 for i=1:numel(x)
0061     if dir == 'v' % vertical errobar
0062     plot([x(i) x(i)], [y(i)-e(i) y(i)+e(i)],color)
0063         switch lower(mark)
0064             case 'i'
0065                 plot([x(i)-dx x(i)+dx], [y(i)-e(i) y(i)-e(i)],color)
0066                 plot([x(i)-dx x(i)+dx], [y(i)+e(i) y(i)+e(i)],color)
0067             case '^'
0068                 plot(x(i), y(i)-e(i),[color,'v'])
0069                 plot(x(i), y(i)+e(i),[color,'^'])
0070             case 'v'
0071                 plot(x(i), y(i)-e(i),[color,'^'])
0072                 plot(x(i), y(i)+e(i),[color,'v'])
0073             otherwise
0074                 plot([x(i) x(i)], [y(i)-e(i) y(i)+e(i)],[color,mark])
0075         end
0076     else    %horizontal errorbar
0077     plot([x(i)-e(i) x(i)+e(i)], [y(i) y(i)],color)
0078         switch lower(mark)
0079             case 'i'
0080                 plot([x(i)-e(i) x(i)-e(i)], [y(i)-dy y(i)+dy],color)
0081                 plot([x(i)+e(i) x(i)+e(i)], [y(i)-dy y(i)+dy],color)
0082             case '<'
0083                 plot(x(i)-e(i), y(i),[color,'<'])
0084                 plot(x(i)+e(i), y(i),[color,'>'])
0085             case '>'
0086                 plot(x(i)-e(i), y(i),[color,'>'])
0087                 plot(x(i)+e(i), y(i),[color,'<'])
0088             otherwise
0089                 plot([x(i)-e(i) x(i)+e(i)], [y(i) y(i)],[color,mark])
0090         end
0091     end
0092 end
0093 hold off

Generated on Thu 21-Jun-2012 15:39:23 by m2html © 2003