plotperc.m 1.4 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354
  1. function plpc=plotperc(xaxis, yvalues, percvals, colorvs, alpha)
  2. if nargin<5
  3. alpha=.1;
  4. end
  5. if nargin>=4 && ischar(colorvs) && contains('kbgcrmyw',colorvs(1))
  6. color=rem(floor((strfind('kbgcrmyw',colorvs(1))-1)*[.25 .5 1]),2);
  7. elseif nargin>=4 && isa(colorvs,'double')
  8. color=colorvs(1:3);
  9. else
  10. color=[0 0 0];
  11. end
  12. if nargin<3
  13. percvals=[05 95];
  14. end
  15. if ~any(size(percvals)==2)
  16. error('percvals input is not correct');
  17. end
  18. if size(percvals,1)==2 && size(percvals,2)~=2
  19. percvals=percvals';
  20. end
  21. % force xaxis and yvalues to have same number of rows (not columns)
  22. if size(yvalues,2)~=length(xaxis)
  23. yvalues=yvalues';
  24. end
  25. if size(yvalues,2)~=length(xaxis)
  26. error('xaxis and yvalues do not match in size');
  27. end
  28. for vv=1:size(percvals,1)
  29. perc2=prctile(yvalues,percvals(vv,2),1);
  30. if(percvals(1)==-inf)
  31. perc1=repmat(min(get(gca,'YLim')),1,length(xaxis));
  32. else
  33. perc1=prctile(yvalues,percvals(vv,1),1);
  34. end
  35. %perc1(perc1<1e-50)=nan; % hardcoded fix for singularities
  36. %perc2(perc2<1e-50)=nan; % hardcoded fix for singularities
  37. pp=[perc1 perc2(end:-1:1)]';
  38. xp=[xaxis xaxis(end:-1:1)]';
  39. hold on;
  40. %fill([xaxis xaxis(end:-1:1)]',[perc1 perc2(end:-1:1)]',color,'facealpha',alpha,'linestyle','none'); hold on;
  41. plpc(vv).fill=fill(xp(isfinite(pp)),pp(isfinite(pp)),color,'facealpha',alpha,'linestyle','none'); hold on;
  42. end
  43. end