Mercurial > hg > octave-lyh
comparison scripts/general/interp1.m @ 14492:7ce925166af6
Fix inconsistent orientation of output matrix for interp1.
* interp1.m: Fix inconsistent orientation of output matrix. Properly include
the extrapolaed values.
author | Olaf Till <i7tiol@t-online.de> |
---|---|
date | Thu, 22 Mar 2012 21:00:52 -0400 |
parents | f3d52523cde1 |
children | 5d3a684236b0 |
comparison
equal
deleted
inserted
replaced
14491:5bd9e47e9277 | 14492:7ce925166af6 |
---|---|
246 endif | 246 endif |
247 | 247 |
248 if (ispp) | 248 if (ispp) |
249 y = shiftdim (reshape (y, szy), 1); | 249 y = shiftdim (reshape (y, szy), 1); |
250 yi = pchip (x, y); | 250 yi = pchip (x, y); |
251 yi.orient = "first"; | |
251 else | 252 else |
252 y = shiftdim (y, 1); | 253 y = shiftdim (y, 1); |
253 yi = pchip (x, y, reshape (xi, szx)); | 254 yi = pchip (x, y, reshape (xi, szx)); |
255 if (! isvector (y)) | |
256 yi = shiftdim (yi, 1); | |
257 endif | |
254 endif | 258 endif |
255 case {"spline", "*spline"} | 259 case {"spline", "*spline"} |
256 if (nx == 2 || starmethod) | 260 if (nx == 2 || starmethod) |
257 x = linspace(x(1), x(nx), ny); | 261 x = linspace(x(1), x(nx), ny); |
258 endif | 262 endif |
259 | 263 |
260 if (ispp) | 264 if (ispp) |
261 y = shiftdim (reshape (y, szy), 1); | 265 y = shiftdim (reshape (y, szy), 1); |
262 yi = spline (x, y); | 266 yi = spline (x, y); |
267 yi.orient = "first"; | |
263 else | 268 else |
264 y = shiftdim (y, 1); | 269 y = shiftdim (y, 1); |
265 yi = spline (x, y, reshape (xi, szx)); | 270 yi = spline (x, y, reshape (xi, szx)); |
271 if (! isvector (y)) | |
272 yi = shiftdim (yi, 1); | |
273 endif | |
266 endif | 274 endif |
267 otherwise | 275 otherwise |
268 error ("interp1: invalid method '%s'", method); | 276 error ("interp1: invalid method '%s'", method); |
269 endswitch | 277 endswitch |
270 | 278 |
278 outliers = xi < minx | ! (xi <= maxx); # this catches even NaNs | 286 outliers = xi < minx | ! (xi <= maxx); # this catches even NaNs |
279 if (size_equal (outliers, yi)) | 287 if (size_equal (outliers, yi)) |
280 yi(outliers) = extrap; | 288 yi(outliers) = extrap; |
281 yi = reshape (yi, szx); | 289 yi = reshape (yi, szx); |
282 elseif (!isvector (yi)) | 290 elseif (!isvector (yi)) |
283 if (strcmp (method, "pchip") || strcmp (method, "*pchip") | 291 yi(outliers, :) = extrap; |
284 ||strcmp (method, "cubic") || strcmp (method, "*cubic") | |
285 ||strcmp (method, "spline") || strcmp (method, "*spline")) | |
286 yi(:, outliers) = extrap; | |
287 yi = shiftdim(yi, 1); | |
288 else | |
289 yi(outliers, :) = extrap; | |
290 endif | |
291 else | 292 else |
292 yi(outliers.') = extrap; | 293 yi(outliers.') = extrap; |
293 endif | 294 endif |
294 endif | 295 endif |
295 else | |
296 yi.orient = "first"; | |
297 endif | 296 endif |
298 | 297 |
299 endfunction | 298 endfunction |
300 | 299 |
301 | 300 |