Mercurial > hg > octave-lyh
diff scripts/polynomial/spline.m @ 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 | 95c3e38098bf |
children | be55736a0783 |
line wrap: on
line diff
--- a/scripts/polynomial/spline.m +++ b/scripts/polynomial/spline.m @@ -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))));