changeset 10658:c66a4657d764

spline.m: Ignore NaNs within input vectors.
author Ben Abbott <bpabbott@mac.com>
date Tue, 25 May 2010 18:14:25 -0400
parents c6833d31f34e
children 8baff2aceabc
files scripts/ChangeLog scripts/polynomial/spline.m
diffstat 2 files changed, 18 insertions(+), 0 deletions(-) [+]
line wrap: on
line diff
--- a/scripts/ChangeLog	Tue May 25 13:46:22 2010 +0200
+++ b/scripts/ChangeLog	Tue May 25 18:14:25 2010 -0400
@@ -1,3 +1,7 @@
+2010-05-25  Ben Abbott <bpabbott@mac.com>
+
+	* polynomial/spline.m: Ignore NaNs within input vectors.
+
 2010-05-25  Jaroslav Hajek  <highegg@gmail.com>
 
 	* specfun/primes.m: Use logical masks rather than numeric.
--- a/scripts/polynomial/spline.m	Tue May 25 13:46:22 2010 +0200
+++ b/scripts/polynomial/spline.m	Tue May 25 18:14:25 2010 -0400
@@ -93,6 +93,12 @@
   else
     a = reshape (y, [prod(szy(1:end-1)), szy(end)]).';
   endif
+  
+  for k = (1:columns (a))(any (isnan (a))) 
+    ok = ! isnan (a(:,k)); 
+    a(!ok,k) = spline (x(ok), a(ok,k), x(!ok)); 
+  endfor 
+  
   complete = false;
   if (size (a, 1) == n + 2)
     complete = true;
@@ -223,3 +229,11 @@
 %!assert (imag(spline(x,y,x.')), imag(y).', abserr);
 %!assert (imag(spline(x.',y.',x.')), imag(y).', abserr);
 %!assert (imag(spline(x.',y,x)), imag(y), abserr);
+%!test
+%! xnan = 5;
+%! y(x==xnan) = NaN;
+%! ok = ! isnan (y);
+%! assert (spline (x, y, x(ok)), y(ok), abserr);
+%!test
+%! ok = ! isnan (y);
+%! assert (! isnan (spline (x, y, x(!ok))));