# HG changeset patch # User jwe # Date 1081265115 0 # Node ID a3440ff5eb142f90ce09d29dd4a9d297f188d75d # Parent 8122518935e43704a7725f277f65643acc5591fc [project @ 2004-04-06 15:23:56 by jwe] diff --git a/scripts/ChangeLog b/scripts/ChangeLog --- a/scripts/ChangeLog +++ b/scripts/ChangeLog @@ -1,3 +1,7 @@ +2004-04-06 David Bateman + + * statistics/base/var.m: Update for NDArrays. Allow dimension arg. + 2004-04-02 David Bateman * statistics/base/std.m: Allow optional args for type and dim. diff --git a/scripts/statistics/base/var.m b/scripts/statistics/base/var.m --- a/scripts/statistics/base/var.m +++ b/scripts/statistics/base/var.m @@ -22,27 +22,54 @@ ## For vector arguments, return the (real) variance of the values. ## For matrix arguments, return a row vector contaning the variance for ## each column. +## +## The argument @var{opt} determines the type of normalization to use. Valid +## values are +## +## @table @asis +## @item 0: +## normalizes with N-1, provides the square root of best unbiased estimator +## of the variance [default] +## @item 1: +## normalizes with N, this provides the square root of the second moment +## around the mean +## @end table +## +## The third argument @var{dim} determines the dimension along which the +## variance is calculated. ## @end deftypefn ## Author: KH ## Description: Compute variance -function y = var(x) +function y = var (x, opt, dim) - if (nargin != 1) - usage ("var (x)"); + if (nargin < 1 || nargin > 3) + usage ("var (x, opt, sim)"); + endif + if (nargin < 3) + dim = min (find (size (x) > 1)); + if (isempty (dim)) + dim = 1; + endif + endif + if (nargin < 2 || isempty (opt)) + opt = 0; endif - [nr, nc] = size (x); - if (nr == 0 || nc == 0) + sz = size (x); + if (prod (sz) < 1) error ("var: x must not be empty"); - elseif ((nr == 1) && (nc == 1)) + elseif (sz(dim) == 1) y = 0; - elseif ((nr == 1) || (nc == 1)) - n = length (x); - y = sumsq (x - sum (x) / n) / (n - 1); else - y = sumsq (x - ones (nr, 1) * (sum (x) / nr) ) / (nr - 1); + rng = ones (1, length (sz)); + rng (dim) = sz (dim); + if (opt == 0) + y = sumsq (x - repmat(mean (x, dim), rng), dim) / (sz(dim) - 1); + else + y = sumsq (x - repmat(mean (x, dim), rng), dim) / sz(dim); + endif endif endfunction diff --git a/src/ChangeLog b/src/ChangeLog --- a/src/ChangeLog +++ b/src/ChangeLog @@ -1,3 +1,8 @@ +2004-04-06 David Bateman + + * DLD_FUNCTIONS/fftn.cc: Save result of transpose operation. + Check for failure of transpose. + 2004-04-02 John W. Eaton * ov-bool.h (octave_bool::bool_array_value): New function. diff --git a/src/DLD-FUNCTIONS/fftn.cc b/src/DLD-FUNCTIONS/fftn.cc --- a/src/DLD-FUNCTIONS/fftn.cc +++ b/src/DLD-FUNCTIONS/fftn.cc @@ -64,9 +64,9 @@ { Matrix val = args(1).matrix_value (); if (val.rows () > val.columns ()) - val.transpose (); + val = val.transpose (); - if (val.columns () != dims.length () || val.rows () != 1) + if (error_state || val.columns () != dims.length () || val.rows () != 1) error ("%s: second argument must be a vector of length dim", fcn); else {