


Computes the mean of each column of a matrix with some NaNs.


0001 function y = nanmean(x) 0002 % Computes the mean of each column of a matrix with some NaNs. 0003 0004 %@info: 0005 %! @deftypefn {Function File} {@var{y} =} nanmean (@var{x}) 0006 %! @anchor{nanmean} 0007 %! @sp 1 0008 %! Computes the mean of each column of a matrix with some NaNs. 0009 %! @sp 2 0010 %! @strong{Inputs} 0011 %! @table @ @var 0012 %! @item x 0013 %! Matlab matrix (T-by-N). 0014 %! @end table 0015 %! @sp 2 0016 %! @strong{Outputs} 0017 %! @table @ @var 0018 %! @item y 0019 %! Matlab vector (1-by-N), the mean. 0020 %! @end table 0021 %! @sp 2 0022 %! @strong{This function is called by:} 0023 %! @sp 1 0024 %! @ref{compute_cova}, @ref{compute_acov}, @ref{compute_std}, @ref{nandemean} 0025 %! @sp 2 0026 %! @strong{This function calls:} 0027 %! @sp 1 0028 %! @ref{ndim} 0029 %! 0030 %! @end deftypefn 0031 %@eod: 0032 0033 % Copyright (C) 2011 Dynare Team 0034 % 0035 % This file is part of Dynare. 0036 % 0037 % Dynare is free software: you can redistribute it and/or modify 0038 % it under the terms of the GNU General Public License as published by 0039 % the Free Software Foundation, either version 3 of the License, or 0040 % (at your option) any later version. 0041 % 0042 % Dynare is distributed in the hope that it will be useful, 0043 % but WITHOUT ANY WARRANTY; without even the implied warranty of 0044 % MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the 0045 % GNU General Public License for more details. 0046 % 0047 % You should have received a copy of the GNU General Public License 0048 % along with Dynare. If not, see <http://www.gnu.org/licenses/>. 0049 0050 % AUTHOR(S) stephane DOT adjemian AT univ DASH lemans DOT fr 0051 0052 switch ndim(x) 0053 case 1 0054 y = mean(x(find(~isnan(x)))); 0055 case 2 0056 y = NaN(1,size(x,2)); 0057 for i = 1:size(x,2) 0058 y(i) = mean(x(find(~isnan(x(:,i))),i)); 0059 end 0060 otherwise 0061 error('descriptive_statistics::nanmean:: This function is not implemented for arrays with dimension greater than two!') 0062 end