[mn,sd,all]=nt_bsmean(x,N) - calculate mean, estimate sd using bootstrap mn: mean of x over second dimension sd: standard deviation from mn of bootstrap trials all: matrix of all bootstrap trials x: matrix of observations (time X repetitions) N: number of bootstrap trials [default: 100]
0001 function [mn,sd,all]=nt_bsmean(x,N) 0002 %[mn,sd,all]=nt_bsmean(x,N) - calculate mean, estimate sd using bootstrap 0003 % 0004 % mn: mean of x over second dimension 0005 % sd: standard deviation from mn of bootstrap trials 0006 % all: matrix of all bootstrap trials 0007 % 0008 % x: matrix of observations (time X repetitions) 0009 % N: number of bootstrap trials [default: 100] 0010 0011 if nargin <2; N=100; end 0012 0013 if ndims(x)>2; 0014 x=squeeze(x); 0015 if ndims(x)>2; 0016 error('data must be at most 2D'); 0017 end 0018 end 0019 0020 [m,n]=size(x); 0021 all=zeros(m,N); 0022 for k=1:N 0023 idx=ceil(n*rand(1,n)); 0024 all(:,k)=mean(x(:,idx),2); 0025 end 0026 0027 mn=mean(x,2); 0028 sd=sqrt(mean((all-repmat(mn,1,N)).^2,2)); 0029 0030