changeset 24111:392afc740749

lsccov.m: ensure all necessary variables are defined (bug #52131) * lscov.m: make sure necessary intermediate variables are defined even when not requested as output.
author Pantxo Diribarne <pantxo.diribarne@gmail.com>
date Thu, 28 Sep 2017 13:22:30 +0200
parents 194558542203
children 2cc851e8e03f
files scripts/statistics/base/lscov.m
diffstat 1 files changed, 18 insertions(+), 19 deletions(-) [+]
line wrap: on
line diff
--- a/scripts/statistics/base/lscov.m	Thu Sep 28 11:04:02 2017 +0200
+++ b/scripts/statistics/base/lscov.m	Thu Sep 28 13:22:30 2017 +0200
@@ -76,10 +76,10 @@
     else
       ## n-by-n covariance matrix
       try
-        ## ordinarily V will be positive definite
+        ## Ordinarily V will be positive definite
         B = chol (V)';
       catch
-        ## if V is only positive semidefinite, use its
+        ## If V is only positive semidefinite, use its
         ## eigendecomposition to find a factor B such that V = B*B'
         [B, lambda] = eig (V);
         image_dims = (diag (lambda) > 0);
@@ -90,28 +90,27 @@
     endif
   endif
 
-  pinv_A = pinv (A); #pseudoinverse
+  pinv_A = pinv (A);
 
   x = pinv_A * b;
 
-  if (isargout (3))
-    dof = n - p; #degrees of freedom remaining after fit
+  if (nargout > 1)
+    dof = n - p;  # degrees of freedom remaining after fit
     SSE = sumsq (b - A * x);
     mse = SSE / dof;
-  endif
-
-  s = pinv_A * pinv_A';
-
-  stdx = sqrt (diag (s) * mse);
-
-  if (isargout (4))
-    if (k == 1)
-      S = mse * s;
-    else
-      S = NaN (p, p, k);
-      for i = 1:k
-        S(:, :, i) = mse(i) * s;
-      endfor
+    
+    s = pinv_A * pinv_A';
+    stdx = sqrt (diag (s) * mse);
+    
+    if (nargout > 3)
+      if (k == 1)
+        S = mse * s;
+      else
+        S = NaN (p, p, k);
+        for i = 1:k
+          S(:, :, i) = mse(i) * s;
+        endfor
+      endif
     endif
   endif