Thu 28 Feb 2013 08:32:07 PM UTC, original submission:
+verbatim
##
##interp1 error demo
##
x=0:0.1:2;
y=[sin(x); cos(x)]';
##call to interp1 reults in a row vector
z = interp1(x, y, 0.5)
##but a call with the option pchip results in a column vector
zp = interp1(x, y, 0.5, 'pchip')
-verbatim
problem is easily corrected by adding transpose .' operation when using pchip or spline options
--- /usr/share/octave/3.6.3/m/general/interp1.m 2012-12-01 21:46:44.000000000 +0200
+++ interp1.m 2013-02-28 19:57:56.075784320 +0200
@@ -247,10 +247,10 @@
if (ispp)
y = shiftdim (reshape (y, szy), 1);
- yi = pchip (x, y);
+ yi = pchip (x, y).';
else
y = shiftdim (y, 1);
- yi = pchip (x, y, reshape (xi, szx));
+ yi = pchip (x, y, reshape (xi, szx)).';
endif
case {"spline", "*spline"}
if (nx == 2 || starmethod)
@@ -259,10 +259,10 @@
if (ispp)
y = shiftdim (reshape (y, szy), 1);
- yi = spline (x, y);
+ yi = spline (x, y).';
else
y = shiftdim (y, 1);
- yi = spline (x, y, reshape (xi, szx));
+ yi = spline (x, y, reshape (xi, szx)).';
endif
otherwise
error ("interp1: invalid method '%s'", method);
|