Home > NoiseTools > nt_bsplot2.m

# nt_bsplot2

## PURPOSE

nt_bsplot(x,percentile,style,abscissa,zeroflag,rmsflag) - plot average with confidence interval

## SYNOPSIS

function nt_bsplot2(x,percentile,style,abscissa,zeroflag,rmsflag)

## DESCRIPTION

    nt_bsplot(x,percentile,style,abscissa,zeroflag,rmsflag) - plot average with confidence interval

      x: data to plot (time * trials, or time * 1 * trials)
      percentile: width of band to plot in standard deviations (default: 2)
      style: 'zerobased' (default) or 'meanbased'
      abscissa: use this vector as plot's abscissa (as in 'plot(abscissa,x)' )
      zeroflag: if 1 draw zero line (default: 1)
      rmsflag: if 1 use RMS instead of mean (default==0)

      Example:
        nt_bsplot(x)
      where x is time*trials will plot the average of x over trials, together
      with +/- 2SDs of the bootstrap resampling.

     NoiseTools.

## CROSS-REFERENCE INFORMATION

This function calls:

- nt_bsmean [mn,sd,all]=nt_bsmean(x,N,w) - calculate mean, estimate sd using bootstrap
- nt_bsrms [rms,sd,all]=nt_bsrms(x,N,w) - calculate rms, estimate sd using bootstrap

This function is called by:

## SOURCE CODE

    0001 function nt_bsplot2(x,percentile,style,abscissa,zeroflag,rmsflag)
    0002 %nt_bsplot(x,percentile,style,abscissa,zeroflag,rmsflag) - plot average with confidence interval
    0003 %
    0004 %  x: data to plot (time * trials, or time * 1 * trials)
    0005 %  percentile: width of band to plot in standard deviations (default: 2)
    0006 %  style: 'zerobased' (default) or 'meanbased'
    0007 %  abscissa: use this vector as plot's abscissa (as in 'plot(abscissa,x)' )
    0008 %  zeroflag: if 1 draw zero line (default: 1)
    0009 %  rmsflag: if 1 use RMS instead of mean (default==0)
    0010 %
    0011 %  Example:
    0012 %    nt_bsplot(x)
    0013 %  where x is time*trials will plot the average of x over trials, together
    0014 %  with +/- 2SDs of the bootstrap resampling.
    0015 %
    0016 % NoiseTools.
    0017
    0018 if nargin<6 || isempty(rmsflag) ; rmsflag=0; end
    0019 if nargin<5 || isempty(zeroflag) ; zeroflag=1; end
    0020 if nargin<4; abscissa=[]; end
    0021 if nargin<3 || isempty(style); style='zerobased'; end
    0022 if nargin<2 || isempty(percentile); percentile=[5 95]; end
    0023
    0024 if numel(percentile)==1
    0025     percentile=[percentile,100-percentile];
    0026 end
    0027
    0028 x=squeeze(x);
    0029 if ndims(x)>2; error('X should have at most 2 non-singleton dimensions'); end
    0030 [m,n]=size(x);
    0031 if n<2; error('bootstrap resampling requires more than 1 column'); end
    0032 if isempty(abscissa); abscissa=1:m; end
    0033 if numel(abscissa) ~= size(x,1); error('abscissa should be same size as x'); end
    0034
    0035 N=1000;
    0036 if rmsflag
    0037     [a,~,c]=nt_bsrms(x,N);
    0038 else
    0039     [a,~,c]=nt_bsmean(x,N);
    0040 end
    0041 percentile
    0042 c=[prctile(c',percentile(1))',prctile(c',percentile(2))'];
    0043 if strcmp(style,'zerobased')
    0044     c=c-repmat(a,1,2);
    0045 elseif strcmp(style,'meanbased');
    0046     ;
    0047 else
    0048     error('!');
    0049 end
    0050 Y=[c(:,1);flipud(c(:,2))];
    0051
    0052 abscissa=abscissa(:);
    0053 X=[abscissa;flipud(abscissa)];
    0054 C=0.7*[1 1 1];
    0055 fill(X,Y,C,'edgecolor','none');
    0056 hold on;
    0057 plot(a*0,'k');
    0058 plot(abscissa,a);
    0059 hold off
    0060
    0061 % return
    0062 %
    0063 % abscissa2=linspace(min(abscissa),max(abscissa),m*2);
    0064 % plot(abscissa2,b,'g');
    0065 % c=get(gca,'children'); set(c(1),'color',[.7 .7 .7])
    0066 % hold on;
    0067 % plot(abscissa,a,'b');
    0068 % if zeroflag;
    0069 %     plot(abscissa,0*a,'k');
    0070 %     c=get(gca,'children'); set(c(1),'color',[.5 .5 .5])
    0071 % end
    0072 % %set(gca,'xlim',[1 m])
    0073 % hold off