1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859 |
- function plms= plotmsem(xaxis, yvalues, colorvs, alpha, linespec, linewidth, mflag)
- %plotmsem plots mean +/- sem with shaded, continuous error bars
- if nargin <7
- if nargin < 6
- if nargin < 5
- if nargin < 4
- alpha=.1;
- end
- linespec='-';
- end
- linewidth=2;
- end
- mflag=1; % plot mean, mflag=2 plot median
- end
- if nargin>=3 && ischar(colorvs) && contains('kbgcrmyw',colorvs(1))
- color=rem(floor((strfind('kbgcrmyw',colorvs(1))-1)*[.25 .5 1]),2);
- if length(colorvs)>1
- linespec=colorvs(2:end);
- end
- elseif nargin>=3 && isa(colorvs,'double')
- color=colorvs(1:3);
- else
- color=[0 0 0];
- end
- if ~isvector(xaxis)
- error('x-axis vector has to be 1D.');
- elseif iscolumn(xaxis)
- xaxis=xaxis';
- end
- if ~ismatrix(yvalues)
- error('y-values matrix has to be 2D.');
- end
- if ~any(size(yvalues)==length(xaxis))
- error('x-axis and y-values must have equal size along 1D (at least).');
- end
- % force xaxis and yvalues to have same number of rows (not columns)
- if size(yvalues,2)~=length(xaxis)
- yvalues=yvalues';
- end
- % mean and sem are computed along rows
- if mflag==1
- myv=nanmean(yvalues,1);
- elseif mflag==2
- myv=nanmedian(yvalues,1);
- end
- semyv=nansem(yvalues,1);
- plms.semfill=fill([xaxis xaxis(end:-1:1)]',[myv-semyv myv(end:-1:1)+semyv(end:-1:1)]',color,'facealpha',alpha,'linestyle','none'); hold on;
- plms.meanline=plot(xaxis,myv,linespec,'Color',color,'Linewidth',linewidth);
- end
|