Mercurial > hg > octave-lyh
changeset 9744:fb3543975ed9
optimize center using bsxfun
author | Jaroslav Hajek <highegg@gmail.com> |
---|---|
date | Tue, 20 Oct 2009 12:35:42 +0200 |
parents | 26abff55f6fe |
children | 30d62079c493 |
files | scripts/ChangeLog scripts/statistics/base/center.m |
diffstat | 2 files changed, 9 insertions(+), 18 deletions(-) [+] |
line wrap: on
line diff
--- a/scripts/ChangeLog +++ b/scripts/ChangeLog @@ -1,3 +1,7 @@ +2009-10-20 Jaroslav Hajek <highegg@gmail.com> + + * statistics/base/center.m: Rewrite using bsxfun. + 2009-10-15 David Bateman <dbateman@free.fr> * plot/__go_draw_axes__.m: Allow line and surface markerfacecolor
--- a/scripts/statistics/base/center.m +++ b/scripts/statistics/base/center.m @@ -1,5 +1,6 @@ ## Copyright (C) 1995, 1996, 1997, 1998, 2000, 2002, 2004, 2005, 2006, ## 2007, 2009 Kurt Hornik +## Copyright (C) 2009 VZLU Prague ## ## This file is part of Octave. ## @@ -36,27 +37,13 @@ endif if (nargin < 2) - t = find (size (x) != 1); - if (isempty (t)) - dim = 1; - else - dim = t(1); - endif + dim = [find(size (x) != 1, 1), 1](1); # First non-singleton dim. endif n = size (x, dim); - if (n == 1) - retval = zeros (size (x)); - elseif (n > 0) - if (isvector (x)) - retval = x - sum (x) / n; - else - mx = sum (x, dim) / n; - idx(1:ndims (x)) = {':'}; - idx{dim} = ones (1, n); - retval = x - mx(idx{:}); - endif + if (n == 0) + retval = x; else - retval = x; + retval = bsxfun (@minus, x, sum (x, dim) / n); endif endfunction