0001 function [mn,sd,all]=nt_bsmean(x,N,w)
0002
0003
0004
0005
0006
0007
0008
0009
0010
0011
0012 if nargin <2; N=100; end
0013 if nargin <3; w=[]; end
0014
0015 if ndims(x)>2;
0016 x=squeeze(x);
0017 if ndims(x)>2;
0018 error('data must be at most 2D');
0019 end
0020 end
0021 if numel(N)>1; error('!'); end
0022
0023 if isempty(w)
0024 [m,n]=size(x);
0025 all=zeros(m,N);
0026 for k=1:N
0027 idx=ceil(n*rand(1,n));
0028 all(:,k)=mean(x(:,idx),2);
0029 end
0030 mn=mean(x,2);
0031 sd=sqrt(mean((all-repmat(mn,1,N)).^2,2));
0032 else
0033 if size(w,2)==1; w=repmat(w,1,size(x,2)); end
0034 if size(w) ~= size(x); error('!'); end
0035 [m,n]=size(x);
0036 all=zeros(m,N);
0037 for k=1:N
0038 idx=ceil(n*rand(1,n));
0039 all(:,k)=nt_wmean(x(:,idx),w(:,idx),2);
0040 end
0041 mn=nt_wmean(x,w,2);
0042 sd=sqrt( mean((all-repmat(mn,1,N)).^2, 2));
0043 end
0044
0045
0046