plotErrorPatch.m 624 B

12345678910111213141516171819202122
  1. function [hLine, hErrorPatch] = plotErrorPatch(hAx, x, y, error, lineColor, patchColor, varargin)
  2. if nargin >= 7
  3. faceAlpha = varargin{1};
  4. else
  5. faceAlpha = 0.5;
  6. end
  7. x=x(:)';
  8. y=y(:)';
  9. error = error(:)';
  10. yUpper = y + error;
  11. yLower = y - error;
  12. yLower = yLower(end:-1:1); % Flip lower bound coordinates to use in pacth function.
  13. yPatch = [yUpper, yLower];
  14. xPatch = [x, x(end:-1:1)]; % Flip x coordinates to use in pacth function.
  15. hold(hAx, 'on');
  16. hErrorPatch = patch(hAx, xPatch, yPatch, patchColor, 'linestyle', 'none', 'FaceAlpha', faceAlpha);
  17. hLine = plot(hAx, x, y, 'color', lineColor);
  18. end