confplot.m 2.5 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384
  1. function varargout = confplot(varargin)
  2. %CONFPLOT Linear plot with continuous confidence/error boundaries.
  3. %
  4. % CONFPLOT(X,Y,L,U) plots the graph of vector X vs. vector Y with
  5. % 'continuous' confidence/error boundaries specified by the vectors
  6. % L and U. L and U contain the lower and upper error ranges for each
  7. % point in Y. The vectors X,Y,L and U must all be the same length.
  8. %
  9. % CONFPLOT(X,Y,E) or CONFPLOT(Y,E) plots Y with error bars [Y-E Y+E].
  10. % CONFPLOT(...,'LineSpec') uses the color and linestyle specified by
  11. % the string 'LineSpec'. See PLOT for possibilities.
  12. %
  13. % H = CONFPLOT(...) returns a vector of line handles.
  14. %
  15. % For example,
  16. % x = 1:0.1:10;
  17. % y = sin(x);
  18. % e = std(y)*ones(size(x));
  19. % confplot(x,y,e)
  20. % draws symmetric continuous confidence/error boundaries of unit standard deviation.
  21. %
  22. % See also ERRORBAR, SEMILOGX, SEMILOGY, LOGLOG, PLOTYY, GRID, CLF, CLC, TITLE,
  23. % XLABEL, YLABEL, AXIS, AXES, HOLD, COLORDEF, LEGEND, SUBPLOT, STEM.
  24. %
  25. % © 2002 - Michele Giugliano, PhD (http://www.giugliano.info) (Bern, Monday Nov 4th, 2002 - 19:02)
  26. % (bug-reports to michele@giugliano.info)
  27. % $Revision: 1.0 $ $Date: 2002/11/11 14:36:08 $
  28. %
  29. if (nargin<2)
  30. disp('ERROR: not enough input arguments!');
  31. return;
  32. end % if
  33. x = []; y = []; z1 = []; z2 = []; spec = '';
  34. switch nargin
  35. case 2
  36. y = varargin{1};
  37. z1 = y + varargin{2};
  38. z2 = y - varargin{2};
  39. x = 1:length(y);
  40. case 3
  41. x = varargin{1};
  42. y = varargin{2};
  43. z1 = y + varargin{3};
  44. z2 = y - varargin{3};
  45. case 4
  46. x = varargin{1};
  47. y = varargin{2};
  48. z1 = y + varargin{4};
  49. z2 = y - varargin{3};
  50. end % switch
  51. if (nargin >= 5)
  52. x = varargin{1};
  53. y = varargin{2};
  54. z1 = y + varargin{4};
  55. z2 = y - varargin{3};
  56. spec = 'ok';
  57. end %
  58. p = plot(x,y,x,z1,x,z2); YLIM = get(gca,'YLim'); delete(p);
  59. a1 = area(x,z1,min(YLIM));
  60. hold on;
  61. set(a1,'LineStyle','none'); set(a1,'FaceColor',[0.9 0.9 0.9]);
  62. a2 = area(x,z2,min(YLIM));
  63. set(a2,'LineStyle','none'); set(a2,'FaceColor',[1 1 1]);
  64. if (~isempty(spec)),
  65. spec = sprintf('p = plot(x,y,varargin{5}');
  66. for i=6:nargin, spec = sprintf('%s,varargin{%d}',spec,i); end % for
  67. spec = sprintf('%s);',spec);
  68. eval(spec);
  69. else p = plot(x,y);
  70. end;
  71. hold off;
  72. %set(gca,'Layer','top','XGrid','on','YGrid','on');
  73. set(gca,'Layer','top');
  74. H = [p, a1, a2];
  75. if (nargout>1) varargout{1} = H; end;