function stde=stderr(x,dim) Returns an estimate of the standard error of the mean of x (i.e. the estimated standard deviation divided by the square root of the number of observations) Required Input: x - A vector or matrix of data Optional Input: dim - The dimension of x that corresponds to observations. For example, the EEGLAB EEG.data matrix has dimenstions electrode x time point x observation, so dim would be 3. {default: 1}
0001 function stde=stderr(x,dim) 0002 %function stde=stderr(x,dim) 0003 % 0004 % Returns an estimate of the standard error of the mean of x (i.e. the 0005 % estimated standard deviation divided by the square root of the number of 0006 % observations) 0007 % 0008 % Required Input: 0009 % x - A vector or matrix of data 0010 % 0011 % Optional Input: 0012 % dim - The dimension of x that corresponds to observations. For example, 0013 % the EEGLAB EEG.data matrix has dimenstions electrode x time point x 0014 % observation, so dim would be 3. {default: 1} 0015 0016 if nargin<2, 0017 dim=1; 0018 end 0019 0020 mx_dim=length(size(x)); 0021 if dim>mx_dim, 0022 error('x has only %d dimensions but argument dim equals %d.',mx_dim,dim); 0023 end 0024 0025 n_obs=size(x,dim); 0026 if n_obs==1, 0027 error('x needs to have more than one element in dimension %d (i.e., the dimension that contains multiple observations)',dim); 0028 end 0029 0030 stde=squeeze(std(x,0,dim))/sqrt(n_obs);