function tsplot(y,x,mode,lColor,tColor) if ~exist('x','var'), x = [1:size(y,1)]; end if ~exist('mode','var'), mode = 'mean+std'; end if ~exist('lColor','var'), lColor = rand(1,3)/2; end if ~exist('tColor','var'), tColor = [lColor,1];end stdy = std(y,1,2)'; semy = stdy/sqrt(size(y,2)); ts = tinv([0.025 0.975],size(y,2)-1); mode = split(mode,'+'); if length(mode) == 1 meanmode = 'mean'; stdmode = mode{1}; elseif length(mode) == 2 meanmode = mode{1}; stdmode = mode{2}; else warning('Undefined tsplot mode, set to [mean + std]') meanmode = 'mean'; stdmode = 'std'; end switch meanmode case 'mean' meany= mean(y,2)'; case 'median' meany= median(y,2)'; end hold on switch stdmode case 'std' fill([x,fliplr(x)],[meany+stdy,fliplr(meany-stdy)],tColor(1:3),'EdgeAlpha',0,'FaceAlpha',tColor(end)/2) case 'sem' fill([x,fliplr(x)],[meany+semy,fliplr(meany-semy)],tColor(1:3),'EdgeAlpha',0,'FaceAlpha',tColor(end)/2) case 'ci' fill([x,fliplr(x)],[meany+ts(1)*semy,fliplr(meany+ts(2)*semy)],tColor(1:3),'EdgeAlpha',0,'FaceAlpha',tColor(end)/2) end plot (x,meany,'color',lColor,'linewidth',2) xlim([min(x),max(x)]) hold off end