Home > matlab > utilities > general > demean.m

demean

PURPOSE ^

Removes the mean of each column of a matrix.

SYNOPSIS ^

function c = demean(x)

DESCRIPTION ^

 Removes the mean of each column of a matrix.

CROSS-REFERENCE INFORMATION ^

This function calls: This function is called by:

SOURCE CODE ^

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

Generated on Tue 22-May-2012 02:40:23 by m2html © 2005