1## Copyright (C) 1995, 1996, 1997, 1998, 2000, 2002, 2004, 2005, 2006,
2## 2007, 2009 Kurt Hornik
3## Copyright (C) 2009 VZLU Prague
5## This file is part of Octave.
7## Octave is free software; you can redistribute it and/or modify it
8## under the terms of the GNU General Public License as published by
9## the Free Software Foundation; either version 3 of the License, or (at
10## your option) any later version.
12## Octave is distributed in the hope that it will be useful, but
13## WITHOUT ANY WARRANTY; without even the implied warranty of
14## MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
15## General Public License for more details.
17## You should have received a copy of the GNU General Public License
18## along with Octave; see the file COPYING. If not, see
19## <http://www.gnu.org/licenses/>.
22## @deftypefn {Function File} {} center (@var{x})
23## @deftypefnx {Function File} {} center (@var{x}, @var{dim})
24## If @var{x} is a vector, subtract its mean.
25## If @var{x} is a matrix, do the above for each column.
26## If the optional argument @var{dim} is given, perform the above
27## operation along this dimension
30## Author: KH <Kurt.Hornik@wu-wien.ac.at>
31## Description: Center by subtracting means
33function retval = center (x, dim)
35 if (nargin != 1 && nargin != 2)
40 dim = [find(size (x) != 1, 1), 1](1); # First non-singleton dim.
47 retval = bsxfun (@minus, x, sum (x, dim) / n);