# HG changeset patch # User Markus Mützel # Date 1627237028 -7200 # Node ID 09b36aa7088a2f0adf87cb9389748d47c07212fe # Parent 0f41e117789f348ac0d935d235b02bd7c04e47a4 interp1.m: Don't interpret later numeric input as "xi" (bug #60967). * scripts/general/interp1.m: Fix input check to potentially interpret only the first optional argument as "xi". Add tests that have numeric "extrap" value. diff -r 0f41e117789f -r 09b36aa7088a scripts/general/interp1.m --- a/scripts/general/interp1.m Thu Jul 22 13:52:49 2021 -0400 +++ b/scripts/general/interp1.m Sun Jul 25 20:17:08 2021 +0200 @@ -126,12 +126,12 @@ extrap = NA; xi = []; ispp = false; - firstnumeric = true; + have_xi = false; rightcontinuous = NaN; if (nargin > 2) - for i = 1:length (varargin) - arg = varargin{i}; + for i_arg = 1:length (varargin) + arg = varargin{i_arg}; if (ischar (arg)) arg = tolower (arg); switch (arg) @@ -147,9 +147,9 @@ method = arg; endswitch else - if (firstnumeric) + if (i_arg == 1) xi = arg; - firstnumeric = false; + have_xi = true; else extrap = arg; endif @@ -157,7 +157,7 @@ endfor endif - if (isempty (xi) && firstnumeric && ! ispp) + if (! have_xi && ! ispp) xi = y; y = x; if (isvector (y)) @@ -524,6 +524,8 @@ %! interp1 (fliplr (xp),fliplr (yp),xi,style),100*eps) %!assert (ppval (interp1 (xp,yp,style,"pp"),xi), %! interp1 (xp,yp,xi,style,"extrap"),10*eps) +%!assert (interp1 (yp, xi, style, 0), ... +%! interp1 (1:numel (yp), yp, xi, style, 0), 10*eps) %!error interp1 (1,1,1, style) ## ENDBLOCK @@ -561,6 +563,8 @@ #%! interp1 (fliplr (xp),fliplr (yp),xi,style),100*eps) %!assert (ppval (interp1 (xp,yp,style,"pp"),xi), %! interp1 (xp,yp,xi,style,"extrap"),10*eps) +%!assert (interp1 (yp, xi, style, 0), ... +%! interp1 (1:numel (yp), yp, xi, style, 0), 10*eps) %!error interp1 (1,1,1, style) ## ENDBLOCK @@ -596,6 +600,8 @@ #%! interp1 (fliplr (xp),fliplr (yp),xi,style),100*eps) %!assert (ppval (interp1 (xp,yp,style,"pp"),xi), %! interp1 (xp,yp,xi,style,"extrap"),10*eps) +%!assert (interp1 (yp, xi, style, 0), ... +%! interp1 (1:numel (yp), yp, xi, style, 0), 10*eps) %!error interp1 (1,1,1, style) ## ENDBLOCK @@ -631,6 +637,8 @@ %! interp1 (fliplr (xp),fliplr (yp),xi,style),100*eps) %!assert (ppval (interp1 (xp,yp,style,"pp"),xi), %! interp1 (xp,yp,xi,style,"extrap"),10*eps) +%!assert (interp1 (yp, xi, style, 0), ... +%! interp1 (1:numel (yp), yp, xi, style, 0), 10*eps) %!assert (interp1 ([1 2 2 3], [1 2 3 4], 2), 3) %!assert (interp1 ([3 2 2 1], [4 3 2 1], 2), 2) %!error interp1 (1,1,1, style) @@ -668,6 +676,8 @@ %! interp1 (fliplr (xp),fliplr (yp),xi,style),100*eps) %!assert (ppval (interp1 (xp,yp,style,"pp"),xi), %! interp1 (xp,yp,xi,style,"extrap"),100*eps) +%!assert (interp1 (yp, xi, style, 0), ... +%! interp1 (1:numel (yp), yp, xi, style, 0), 10*eps) %!error interp1 (1,1,1, style) ## ENDBLOCK @@ -703,6 +713,8 @@ %! interp1 (fliplr (xp),fliplr (yp),xi,style),100*eps) %!assert (ppval (interp1 (xp,yp,style,"pp"),xi), %! interp1 (xp,yp,xi,style,"extrap"),10*eps) +%!assert (interp1 (yp, xi, style, 0), ... +%! interp1 (1:numel (yp), yp, xi, style, 0), 10*eps) %!error interp1 (1,1,1, style) ## ENDBLOCK @@ -738,6 +750,8 @@ %! interp1 (fliplr (xp),fliplr (yp),xi,style),100*eps) %!assert (ppval (interp1 (xp,yp,style,"pp"),xi), %! interp1 (xp,yp,xi,style,"extrap"),10*eps) +%!assert (interp1 (yp, xi, style, 0), ... +%! interp1 (1:numel (yp), yp, xi, style, 0), 10*eps) %!error interp1 (1,1,1, style) ## ENDBLOCK ## ENDBLOCKTEST