changeset 1057:750ebc804b2d octave-forge

use of sum square for complex data improved; check of input arguments simplified
author schloegl
date Fri, 26 Sep 2003 07:42:22 +0000
parents 84d5d1dd6776
children fcf87b82e558
files extra/NaN/std.m extra/NaN/sumskipnan.m extra/NaN/var.m
diffstat 3 files changed, 22 insertions(+), 29 deletions(-) [+]
line wrap: on
line diff
--- a/extra/NaN/std.m	Fri Sep 26 07:41:23 2003 +0000
+++ b/extra/NaN/std.m	Fri Sep 26 07:42:22 2003 +0000
@@ -58,7 +58,7 @@
         end;
 end;
 
-y = (y - s.*s./n);   % n * (summed squares with removed mean)
+y = (y - (real(s).^2+imag(s).^2)./n);   % n * (summed squares with removed mean)
 
 if opt==0, 
         % square root if the best unbiased estimator of the variance 
--- a/extra/NaN/sumskipnan.m	Fri Sep 26 07:41:23 2003 +0000
+++ b/extra/NaN/sumskipnan.m	Fri Sep 26 07:42:22 2003 +0000
@@ -53,13 +53,12 @@
 %	$Id$
 %    Copyright (C) 2000-2003 by Alois Schloegl <a.schloegl@ieee.org>	
 
+
 
-if nargin<2,
-        DIM=min(find(size(i)>1));
-        if isempty(DIM), DIM=1; end;
+if nargin<2,
+        DIM = [];
 end;
-
-
+
 DONE = 0; 
 if flag_implicit_skip_nan & (exist('sumskipnan2')==3);
                 
@@ -98,6 +97,10 @@
 
    
 if ~DONE, % else  
+        if isempty(DIM),
+                DIM=min(find(size(i)>1));
+                if isempty(DIM), DIM = 1; end;
+        end;
         if nargout>1
                 count = sum(~isnan(i),DIM); 
         end;
@@ -106,7 +109,7 @@
         end;
         o = sum(i,DIM);
         if nargout>2,
-                i = i.^2;
+                i = real(i).^2 + imag(i).^2;
                 SSQ = sum(i,DIM);
                 if nargout>3,
                         S4M = sum(i.^2,DIM);
--- a/extra/NaN/var.m	Fri Sep 26 07:41:23 2003 +0000
+++ b/extra/NaN/var.m	Fri Sep 26 07:42:22 2003 +0000
@@ -37,32 +37,22 @@
 %	$Id$
 %	Copyright (C) 2000-2003 by  Alois Schloegl  <a.schloegl@ieee.org>	
 
-ver = version;
-if nargin < 3,
-        DIM = [];
-        if nargin==2,
-                if ~isempty(opt) & opt~=0, 
-                        fprintf(2,'Warning STD: OPTION not supported.\n');
-                end;
-        end;
-elseif nargin == 3,
-        if ~isnumeric(DIM),
-                DIM = [];
-        end
+if nargin>1,
+        if ~isempty(opt) & opt~=0, 
+                fprintf(2,'Warning STD: OPTION not supported.\n');
+        end;
+else 
+        opt = 0; 
+end;
+
+if nargin > 2,
+        [s,n,y] = sumskipnan(x, DIM);
 else
-        fprintf(2,'Error VAR: invalid number of arguments\n usage: v=var(x [,DIM])\n');
+	[s,n,y] = sumskipnan(x);
 end
 
-% obtain which DIMENSION should be used
-if isempty(DIM), 
-        DIM = min(find(size(x)>1));
-        if isempty(DIM), DIM=1; end;
-end;
-
 % actual calculation 
-[s,n,y] = sumskipnan(x, DIM);
-m = s./n;	% mean
-y = (y-s.*m);   % n * (summed squares with removed mean)
+y = (y - (real(s).^2+imag(s).^2)./n);   % n * (summed squares with removed mean)
 
 %if flag_implicit_unbiased_estim;    %% ------- unbiased estimates ----------- 
     n = max(n-1,0);			% in case of n=0 and n=1, the (biased) variance, STD and STE are INF