plotFilled.m 828 B

1234567891011121314151617181920212223242526
  1. function hOut = plotFilled(x, data, color, figHandle)
  2. % plotFilled Plots mean +/- SEM as a filled plot
  3. % hOut = plotFilled(x, data, color, figHandle)
  4. % INPUTS
  5. % x: x data
  6. % data: y data as a n x x vector (n: independent observations, x: x coordinate data)
  7. % color: 1x3 vector from [0 0 0] to [1 1 1]
  8. % figHandle: optional input
  9. % OUTPUTS
  10. % hOut: handle to plot command
  11. if iscell(data) % if this is a cell
  12. y = cellfun(@nanmean, data);
  13. yU = y + cellfun(@sem, data);
  14. yL = y - cellfun(@sem, data);
  15. else
  16. y = nanmean(data);
  17. yU = y + sem(data);
  18. yL = y - sem(data);
  19. end
  20. if nargin > 3
  21. subplot(figHandle)
  22. end
  23. hOut = plot(x, y, 'Color', color, 'linewidth', 2);
  24. fill([x fliplr(x)], [yU fliplr(yL)], color, 'facealpha', 0.25, 'edgecolor', 'none')