changeset 18633:5fe907167520 stable

interp1.m: fix function for inputs w/multiple discontinuities (bug #41980). * interp1.m: Remove discontinuities from dy in the same order as they are removed from xx and yy. Adjust %!tests to account for new behavior.
author Juan Pablo Carbajal <ajuanpi+dev@gmail.com>
date Sun, 30 Mar 2014 23:25:00 +0200
parents 6fdd3ab55b78
children 5b6901b06106 60562e5c8bfb
files scripts/general/interp1.m
diffstat 1 files changed, 7 insertions(+), 6 deletions(-) [+]
line wrap: on
line diff
--- a/scripts/general/interp1.m	Sat Apr 05 17:03:15 2014 -0400
+++ b/scripts/general/interp1.m	Sun Mar 30 23:25:00 2014 +0200
@@ -247,20 +247,21 @@
     case "linear"
 
       xx = x;
+      nxx = nx;
       yy = y;
-      nxx = nx;
+      dy = diff (yy);
       if (have_jumps)
         ## Omit zero-size intervals.
-        yy(jumps, :) = [];
         xx(jumps) = [];
         nxx = rows (xx);
+        yy(jumps, :) = [];
+        dy(jumps, :) = [];
       endif
 
-      dy = diff (yy);
       dx = diff (xx);
       dx = repmat (dx, [1 size(dy)(2:end)]);
 
-      coefs = [(dy./dx).'(:), yy(1:nxx-1, :).'(:)];
+      coefs = [(dy./dx).', yy(1:nxx-1, :).'];
 
       pp = mkpp (xx, coefs, szy(2:end));
       pp.orient = "first";
@@ -631,8 +632,8 @@
 %!assert (interp1 (0:4, 2.5), 1.5)
 
 ## Left and Right discontinuities
-%!assert (interp1 ([1,2,2,3,4],[0,1,4,2,1],[-1,1.5,2,2.5,3.5], "linear", "extrap", "right"), [-8,2,4,3,1.5])
-%!assert (interp1 ([1,2,2,3,4],[0,1,4,2,1],[-1,1.5,2,2.5,3.5], "linear", "extrap", "left"), [-2,0.5,1,1.5,1.5])
+%!assert (interp1 ([1,2,2,3,4],[0,1,4,2,1],[-1,1.5,2,2.5,3.5], "linear", "extrap", "right"), [-2,0.5,4,3,1.5])
+%!assert (interp1 ([1,2,2,3,4],[0,1,4,2,1],[-1,1.5,2,2.5,3.5], "linear", "extrap", "left"), [-2,0.5,1,3,1.5])
 
 %% Test input validation
 %!error interp1 ()