Mercurial > hg > octave-nkf
comparison scripts/general/interp1.m @ 6374:419017274c1e
[project @ 2007-03-01 15:57:50 by jwe]
author | jwe |
---|---|
date | Thu, 01 Mar 2007 15:57:50 +0000 |
parents | 06f26e174fc9 |
children | b2391d403ed2 |
comparison
equal
deleted
inserted
replaced
6373:b3c37bc17c5f | 6374:419017274c1e |
---|---|
186 idx = lookup (0.5*(x(1:nx-1)+x(2:nx)), xi) + 1; | 186 idx = lookup (0.5*(x(1:nx-1)+x(2:nx)), xi) + 1; |
187 yi(range,:) = y(idx,:); | 187 yi(range,:) = y(idx,:); |
188 endif | 188 endif |
189 elseif (strcmp (method, "*nearest")) | 189 elseif (strcmp (method, "*nearest")) |
190 if (pp) | 190 if (pp) |
191 yi = mkpp ([minx; minx+[0.5:(ny-1)]'*dx; maxx], y, szy(2:end)); | 191 yi = mkpp ([x(1); x(1)+[0.5:(ny-1)]'*dx; x(nx)], y, szy(2:end)); |
192 else | 192 else |
193 idx = max (1, min (ny, floor((xi-minx)/dx+1.5))); | 193 idx = max (1, min (ny, floor((xi-x(1))/dx+1.5))); |
194 yi(range,:) = y(idx,:); | 194 yi(range,:) = y(idx,:); |
195 endif | 195 endif |
196 elseif (strcmp (method, "linear")) | 196 elseif (strcmp (method, "linear")) |
197 dy = y(2:ny,:) - y(1:ny-1,:); | 197 dy = y(2:ny,:) - y(1:ny-1,:); |
198 dx = x(2:nx) - x(1:nx-1); | 198 dx = x(2:nx) - x(1:nx-1); |
208 yi(range,:) = s(:,ones(1,nc)).*dy(idx,:) + y(idx,:); | 208 yi(range,:) = s(:,ones(1,nc)).*dy(idx,:) + y(idx,:); |
209 endif | 209 endif |
210 elseif (strcmp (method, "*linear")) | 210 elseif (strcmp (method, "*linear")) |
211 if (pp) | 211 if (pp) |
212 dy = [y(2:ny,:) - y(1:ny-1,:)]; | 212 dy = [y(2:ny,:) - y(1:ny-1,:)]; |
213 yi = mkpp (minx + [0:ny-1]*dx, [dy./dx, y(1:end-1)], szy(2:end)); | 213 yi = mkpp (x(1) + [0:ny-1]*dx, [dy./dx, y(1:end-1)], szy(2:end)); |
214 else | 214 else |
215 ## find the interval containing the test point | 215 ## find the interval containing the test point |
216 t = (xi - minx)/dx + 1; | 216 t = (xi - x(1))/dx + 1; |
217 idx = max(1,min(ny,floor(t))); | 217 idx = max(1,min(ny,floor(t))); |
218 | 218 |
219 ## use the endpoints of the interval to define a line | 219 ## use the endpoints of the interval to define a line |
220 dy = [y(2:ny,:) - y(1:ny-1,:); y(ny,:) - y(ny-1,:)]; | 220 dy = [y(2:ny,:) - y(1:ny-1,:); y(ny,:) - y(ny-1,:)]; |
221 s = t - idx; | 221 s = t - idx; |
222 yi(range,:) = s(:,ones(1,nc)).*dy(idx,:) + y(idx,:); | 222 yi(range,:) = s(:,ones(1,nc)).*dy(idx,:) + y(idx,:); |
223 endif | 223 endif |
224 elseif (strcmp (method, "pchip") || strcmp (method, "*pchip")) | 224 elseif (strcmp (method, "pchip") || strcmp (method, "*pchip")) |
225 if (nx == 2 || method(1) == "*") | 225 if (nx == 2 || method(1) == "*") |
226 x = linspace (minx, maxx, ny); | 226 x = linspace (x(1), x(nx), ny); |
227 endif | 227 endif |
228 ## Note that pchip's arguments are transposed relative to interp1 | 228 ## Note that pchip's arguments are transposed relative to interp1 |
229 if (pp) | 229 if (pp) |
230 yi = pchip (x.', y.'); | 230 yi = pchip (x.', y.'); |
231 yi.d = szy(2:end); | 231 yi.d = szy(2:end); |
234 endif | 234 endif |
235 | 235 |
236 elseif (strcmp (method, "cubic") || (strcmp (method, "*cubic") && pp)) | 236 elseif (strcmp (method, "cubic") || (strcmp (method, "*cubic") && pp)) |
237 ## FIXME Is there a better way to treat pp return return and *cubic | 237 ## FIXME Is there a better way to treat pp return return and *cubic |
238 if (method(1) == "*") | 238 if (method(1) == "*") |
239 x = linspace (minx, maxx, ny).'; | 239 x = linspace (x(1), x(nx), ny).'; |
240 nx = ny; | 240 nx = ny; |
241 endif | 241 endif |
242 | 242 |
243 if (nx < 4 || ny < 4) | 243 if (nx < 4 || ny < 4) |
244 error ("interp1: table too short"); | 244 error ("interp1: table too short"); |
275 error ("interp1: table too short"); | 275 error ("interp1: table too short"); |
276 endif | 276 endif |
277 | 277 |
278 ## From: Miloje Makivic | 278 ## From: Miloje Makivic |
279 ## http://www.npac.syr.edu/projects/nasa/MILOJE/final/node36.html | 279 ## http://www.npac.syr.edu/projects/nasa/MILOJE/final/node36.html |
280 t = (xi - minx)/dx + 1; | 280 t = (xi - x(1))/dx + 1; |
281 idx = max (min (floor (t), ny-2), 2); | 281 idx = max (min (floor (t), ny-2), 2); |
282 t = t - idx; | 282 t = t - idx; |
283 t2 = t.*t; | 283 t2 = t.*t; |
284 tp = 1 - 0.5*t; | 284 tp = 1 - 0.5*t; |
285 a = (1 - t2).*tp; | 285 a = (1 - t2).*tp; |
291 yi(range,:) = a(:,J) .* y(idx,:) + b(:,J) .* y(idx+1,:) ... | 291 yi(range,:) = a(:,J) .* y(idx,:) + b(:,J) .* y(idx+1,:) ... |
292 + c(:,J) .* y(idx-1,:) + d(:,J) .* y(idx+2,:); | 292 + c(:,J) .* y(idx-1,:) + d(:,J) .* y(idx+2,:); |
293 | 293 |
294 elseif (strcmp (method, "spline") || strcmp (method, "*spline")) | 294 elseif (strcmp (method, "spline") || strcmp (method, "*spline")) |
295 if (nx == 2 || method(1) == "*") | 295 if (nx == 2 || method(1) == "*") |
296 x = linspace(minx, maxx, ny); | 296 x = linspace(x(1), x(nx), ny); |
297 endif | 297 endif |
298 ## Note that spline's arguments are transposed relative to interp1 | 298 ## Note that spline's arguments are transposed relative to interp1 |
299 if (pp) | 299 if (pp) |
300 yi = spline (x.', y.'); | 300 yi = spline (x.', y.'); |
301 yi.d = szy(2:end); | 301 yi.d = szy(2:end); |
342 %! plot(xf,yf,";*original;",xf,near,";*nearest;",xf,lin,";*linear;",... | 342 %! plot(xf,yf,";*original;",xf,near,";*nearest;",xf,lin,";*linear;",... |
343 %! xf,cub,";*cubic;",xf,spl,";*spline;",xp,yp,"*;;"); | 343 %! xf,cub,";*cubic;",xf,spl,";*spline;",xp,yp,"*;;"); |
344 %! %-------------------------------------------------------- | 344 %! %-------------------------------------------------------- |
345 %! % confirm that interpolated function matches the original | 345 %! % confirm that interpolated function matches the original |
346 | 346 |
347 ## For each type of interpolated test, confirm that the interpolated | |
348 ## value at the knots match the values at the knots. Points away | |
349 ## from the knots are requested, but only 'nearest' and 'linear' | |
350 ## confirm they are the correct values. | |
351 | |
347 %!shared xp, yp, xi, style | 352 %!shared xp, yp, xi, style |
348 %! xp=0:5; yp = sin(2*pi*xp/5); | 353 %! xp=0:2:10; yp = sin(2*pi*xp/5); |
349 %! xi = sort([-1, max(xp)*rand(1,6), max(xp)+1]); | 354 %! xi = [-1, 0, 2.2, 4, 6.6, 10, 11]; |
350 | 355 |
356 | |
357 ## The following BLOCK/ENDBLOCK section is repeated for each style | |
358 ## nearest, linear, cubic, spline, pchip | |
359 ## The test for ppval of cubic has looser tolerance, but otherwise | |
360 ## the tests are identical. | |
361 ## Note that the block checks style and *style; if you add more tests | |
362 ## before to add them to both sections of each block. One test, | |
363 ## style vs. *style, occurs only in the first section. | |
364 ## There is an ENDBLOCKTEST after the final block | |
351 %!test style = "nearest"; | 365 %!test style = "nearest"; |
352 %!assert (interp1(xp, yp, [min(xp)-1, max(xp)+1]), [NaN, NaN]); | 366 ## BLOCK |
353 %!assert (interp1(xp,yp,xp,style), yp, 100*eps); | 367 %!assert (interp1(xp, yp, [min(xp)-1, max(xp)+1],style), [NaN, NaN]); |
354 %!assert (interp1(xp,yp,xp',style), yp', 100*eps); | 368 %!assert (interp1(xp,yp,xp,style), yp, 100*eps); |
355 %!assert (interp1(xp',yp',xp',style), yp', 100*eps); | 369 %!assert (interp1(xp,yp,xp',style), yp', 100*eps); |
356 %!assert (interp1(xp',yp',xp,style), yp, 100*eps); | 370 %!assert (interp1(xp',yp',xp',style), yp', 100*eps); |
357 %!assert (isempty(interp1(xp',yp',[],style))); | 371 %!assert (interp1(xp',yp',xp,style), yp, 100*eps); |
358 %!assert (isempty(interp1(xp,yp,[],style))); | 372 %!assert (isempty(interp1(xp',yp',[],style))); |
359 %!assert (interp1(xp,[yp',yp'],xi(:),style),... | 373 %!assert (isempty(interp1(xp,yp,[],style))); |
360 %! [interp1(xp,yp,xi(:),style),interp1(xp,yp,xi(:),style)]); | 374 %!assert (interp1(xp,[yp',yp'],xi(:),style),... |
361 %!assert (interp1(xp,[yp',yp'],xi,style), | 375 %! [interp1(xp,yp,xi(:),style),interp1(xp,yp,xi(:),style)]); |
362 %! interp1(xp,[yp',yp'],xi,["*",style])); | 376 %!assert (interp1(xp,yp,xi,style),... |
363 | 377 %! interp1(fliplr(xp),fliplr(yp),xi,style),100*eps); |
364 %!test style = "linear"; | 378 %!assert (ppval(interp1(xp,yp,style,"pp"),xi), |
365 %!assert (interp1(xp, yp, [-1, max(xp)+1]), [NaN, NaN]); | 379 %! interp1(xp,yp,xi,style,"extrap"),10*eps); |
366 %!assert (interp1(xp,yp,xp,style), yp, 100*eps); | 380 %!error interp1(1,1,1, style); |
367 %!assert (interp1(xp,yp,xp',style), yp', 100*eps); | |
368 %!assert (interp1(xp',yp',xp',style), yp', 100*eps); | |
369 %!assert (interp1(xp',yp',xp,style), yp, 100*eps); | |
370 %!assert (isempty(interp1(xp',yp',[],style))); | |
371 %!assert (isempty(interp1(xp,yp,[],style))); | |
372 %!assert (interp1(xp,[yp',yp'],xi(:),style),... | |
373 %! [interp1(xp,yp,xi(:),style),interp1(xp,yp,xi(:),style)]); | |
374 %!assert (interp1(xp,[yp',yp'],xi,style), | 381 %!assert (interp1(xp,[yp',yp'],xi,style), |
375 %! interp1(xp,[yp',yp'],xi,["*",style]),100*eps); | 382 %! interp1(xp,[yp',yp'],xi,["*",style]),100*eps); |
376 | 383 %!test style=['*',style]; |
377 %!test style = "cubic"; | 384 %!assert (interp1(xp, yp, [min(xp)-1, max(xp)+1],style), [NaN, NaN]); |
378 %!assert (interp1(xp, yp, [-1, max(xp)+1]), [NaN, NaN]); | 385 %!assert (interp1(xp,yp,xp,style), yp, 100*eps); |
379 %!assert (interp1(xp,yp,xp,style), yp, 100*eps); | 386 %!assert (interp1(xp,yp,xp',style), yp', 100*eps); |
380 %!assert (interp1(xp,yp,xp',style), yp', 100*eps); | 387 %!assert (interp1(xp',yp',xp',style), yp', 100*eps); |
381 %!assert (interp1(xp',yp',xp',style), yp', 100*eps); | 388 %!assert (interp1(xp',yp',xp,style), yp, 100*eps); |
382 %!assert (interp1(xp',yp',xp,style), yp, 100*eps); | 389 %!assert (isempty(interp1(xp',yp',[],style))); |
383 %!assert (isempty(interp1(xp',yp',[],style))); | 390 %!assert (isempty(interp1(xp,yp,[],style))); |
384 %!assert (isempty(interp1(xp,yp,[],style))); | 391 %!assert (interp1(xp,[yp',yp'],xi(:),style),... |
385 %!assert (interp1(xp,[yp',yp'],xi(:),style),... | 392 %! [interp1(xp,yp,xi(:),style),interp1(xp,yp,xi(:),style)]); |
386 %! [interp1(xp,yp,xi(:),style),interp1(xp,yp,xi(:),style)]); | 393 %!assert (interp1(xp,yp,xi,style),... |
394 %! interp1(fliplr(xp),fliplr(yp),xi,style),100*eps); | |
395 %!assert (ppval(interp1(xp,yp,style,"pp"),xi), | |
396 %! interp1(xp,yp,xi,style,"extrap"),10*eps); | |
397 %!error interp1(1,1,1, style); | |
398 ## ENDBLOCK | |
399 %!test style='linear'; | |
400 ## BLOCK | |
401 %!assert (interp1(xp, yp, [min(xp)-1, max(xp)+1],style), [NaN, NaN]); | |
402 %!assert (interp1(xp,yp,xp,style), yp, 100*eps); | |
403 %!assert (interp1(xp,yp,xp',style), yp', 100*eps); | |
404 %!assert (interp1(xp',yp',xp',style), yp', 100*eps); | |
405 %!assert (interp1(xp',yp',xp,style), yp, 100*eps); | |
406 %!assert (isempty(interp1(xp',yp',[],style))); | |
407 %!assert (isempty(interp1(xp,yp,[],style))); | |
408 %!assert (interp1(xp,[yp',yp'],xi(:),style),... | |
409 %! [interp1(xp,yp,xi(:),style),interp1(xp,yp,xi(:),style)]); | |
410 %!assert (interp1(xp,yp,xi,style),... | |
411 %! interp1(fliplr(xp),fliplr(yp),xi,style),100*eps); | |
412 %!assert (ppval(interp1(xp,yp,style,"pp"),xi), | |
413 %! interp1(xp,yp,xi,style,"extrap"),10*eps); | |
414 %!error interp1(1,1,1, style); | |
387 %!assert (interp1(xp,[yp',yp'],xi,style), | 415 %!assert (interp1(xp,[yp',yp'],xi,style), |
388 %! interp1(xp,[yp',yp'],xi,["*",style]),1000*eps); | 416 %! interp1(xp,[yp',yp'],xi,["*",style]),100*eps); |
389 | 417 %!test style=['*',style]; |
390 %!test style = "spline"; | 418 %!assert (interp1(xp, yp, [min(xp)-1, max(xp)+1],style), [NaN, NaN]); |
391 %!assert (interp1(xp, yp, [-1, max(xp) + 1]), [NaN, NaN]); | 419 %!assert (interp1(xp,yp,xp,style), yp, 100*eps); |
392 %!assert (interp1(xp,yp,xp,style), yp, 100*eps); | 420 %!assert (interp1(xp,yp,xp',style), yp', 100*eps); |
393 %!assert (interp1(xp,yp,xp',style), yp', 100*eps); | 421 %!assert (interp1(xp',yp',xp',style), yp', 100*eps); |
394 %!assert (interp1(xp',yp',xp',style), yp', 100*eps); | 422 %!assert (interp1(xp',yp',xp,style), yp, 100*eps); |
395 %!assert (interp1(xp',yp',xp,style), yp, 100*eps); | 423 %!assert (isempty(interp1(xp',yp',[],style))); |
396 %!assert (isempty(interp1(xp',yp',[],style))); | 424 %!assert (isempty(interp1(xp,yp,[],style))); |
397 %!assert (isempty(interp1(xp,yp,[],style))); | 425 %!assert (interp1(xp,[yp',yp'],xi(:),style),... |
398 %!assert (interp1(xp,[yp',yp'],xi(:),style),... | 426 %! [interp1(xp,yp,xi(:),style),interp1(xp,yp,xi(:),style)]); |
399 %! [interp1(xp,yp,xi(:),style),interp1(xp,yp,xi(:),style)]); | 427 %!assert (interp1(xp,yp,xi,style),... |
428 %! interp1(fliplr(xp),fliplr(yp),xi,style),100*eps); | |
429 %!assert (ppval(interp1(xp,yp,style,"pp"),xi), | |
430 %! interp1(xp,yp,xi,style,"extrap"),10*eps); | |
431 %!error interp1(1,1,1, style); | |
432 ## ENDBLOCK | |
433 %!test style='cubic'; | |
434 ## BLOCK | |
435 %!assert (interp1(xp, yp, [min(xp)-1, max(xp)+1],style), [NaN, NaN]); | |
436 %!assert (interp1(xp,yp,xp,style), yp, 100*eps); | |
437 %!assert (interp1(xp,yp,xp',style), yp', 100*eps); | |
438 %!assert (interp1(xp',yp',xp',style), yp', 100*eps); | |
439 %!assert (interp1(xp',yp',xp,style), yp, 100*eps); | |
440 %!assert (isempty(interp1(xp',yp',[],style))); | |
441 %!assert (isempty(interp1(xp,yp,[],style))); | |
442 %!assert (interp1(xp,[yp',yp'],xi(:),style),... | |
443 %! [interp1(xp,yp,xi(:),style),interp1(xp,yp,xi(:),style)]); | |
444 %!assert (interp1(xp,yp,xi,style),... | |
445 %! interp1(fliplr(xp),fliplr(yp),xi,style),100*eps); | |
446 %!assert (ppval(interp1(xp,yp,style,"pp"),xi), | |
447 %! interp1(xp,yp,xi,style,"extrap"),100*eps); | |
448 %!error interp1(1,1,1, style); | |
400 %!assert (interp1(xp,[yp',yp'],xi,style), | 449 %!assert (interp1(xp,[yp',yp'],xi,style), |
401 %! interp1(xp,[yp',yp'],xi,["*",style]),10*eps); | 450 %! interp1(xp,[yp',yp'],xi,["*",style]),100*eps); |
451 %!test style=['*',style]; | |
452 %!assert (interp1(xp, yp, [min(xp)-1, max(xp)+1],style), [NaN, NaN]); | |
453 %!assert (interp1(xp,yp,xp,style), yp, 100*eps); | |
454 %!assert (interp1(xp,yp,xp',style), yp', 100*eps); | |
455 %!assert (interp1(xp',yp',xp',style), yp', 100*eps); | |
456 %!assert (interp1(xp',yp',xp,style), yp, 100*eps); | |
457 %!assert (isempty(interp1(xp',yp',[],style))); | |
458 %!assert (isempty(interp1(xp,yp,[],style))); | |
459 %!assert (interp1(xp,[yp',yp'],xi(:),style),... | |
460 %! [interp1(xp,yp,xi(:),style),interp1(xp,yp,xi(:),style)]); | |
461 %!assert (interp1(xp,yp,xi,style),... | |
462 %! interp1(fliplr(xp),fliplr(yp),xi,style),100*eps); | |
463 %!assert (ppval(interp1(xp,yp,style,"pp"),xi), | |
464 %! interp1(xp,yp,xi,style,"extrap"),100*eps); | |
465 %!error interp1(1,1,1, style); | |
466 ## ENDBLOCK | |
467 %!test style='pchip'; | |
468 ## BLOCK | |
469 %!assert (interp1(xp, yp, [min(xp)-1, max(xp)+1],style), [NaN, NaN]); | |
470 %!assert (interp1(xp,yp,xp,style), yp, 100*eps); | |
471 %!assert (interp1(xp,yp,xp',style), yp', 100*eps); | |
472 %!assert (interp1(xp',yp',xp',style), yp', 100*eps); | |
473 %!assert (interp1(xp',yp',xp,style), yp, 100*eps); | |
474 %!assert (isempty(interp1(xp',yp',[],style))); | |
475 %!assert (isempty(interp1(xp,yp,[],style))); | |
476 %!assert (interp1(xp,[yp',yp'],xi(:),style),... | |
477 %! [interp1(xp,yp,xi(:),style),interp1(xp,yp,xi(:),style)]); | |
478 %!assert (interp1(xp,yp,xi,style),... | |
479 %! interp1(fliplr(xp),fliplr(yp),xi,style),100*eps); | |
480 %!assert (ppval(interp1(xp,yp,style,"pp"),xi), | |
481 %! interp1(xp,yp,xi,style,"extrap"),10*eps); | |
482 %!error interp1(1,1,1, style); | |
483 %!assert (interp1(xp,[yp',yp'],xi,style), | |
484 %! interp1(xp,[yp',yp'],xi,["*",style]),100*eps); | |
485 %!test style=['*',style]; | |
486 %!assert (interp1(xp, yp, [min(xp)-1, max(xp)+1],style), [NaN, NaN]); | |
487 %!assert (interp1(xp,yp,xp,style), yp, 100*eps); | |
488 %!assert (interp1(xp,yp,xp',style), yp', 100*eps); | |
489 %!assert (interp1(xp',yp',xp',style), yp', 100*eps); | |
490 %!assert (interp1(xp',yp',xp,style), yp, 100*eps); | |
491 %!assert (isempty(interp1(xp',yp',[],style))); | |
492 %!assert (isempty(interp1(xp,yp,[],style))); | |
493 %!assert (interp1(xp,[yp',yp'],xi(:),style),... | |
494 %! [interp1(xp,yp,xi(:),style),interp1(xp,yp,xi(:),style)]); | |
495 %!assert (interp1(xp,yp,xi,style),... | |
496 %! interp1(fliplr(xp),fliplr(yp),xi,style),100*eps); | |
497 %!assert (ppval(interp1(xp,yp,style,"pp"),xi), | |
498 %! interp1(xp,yp,xi,style,"extrap"),10*eps); | |
499 %!error interp1(1,1,1, style); | |
500 ## ENDBLOCK | |
501 %!test style='spline'; | |
502 ## BLOCK | |
503 %!assert (interp1(xp, yp, [min(xp)-1, max(xp)+1],style), [NaN, NaN]); | |
504 %!assert (interp1(xp,yp,xp,style), yp, 100*eps); | |
505 %!assert (interp1(xp,yp,xp',style), yp', 100*eps); | |
506 %!assert (interp1(xp',yp',xp',style), yp', 100*eps); | |
507 %!assert (interp1(xp',yp',xp,style), yp, 100*eps); | |
508 %!assert (isempty(interp1(xp',yp',[],style))); | |
509 %!assert (isempty(interp1(xp,yp,[],style))); | |
510 %!assert (interp1(xp,[yp',yp'],xi(:),style),... | |
511 %! [interp1(xp,yp,xi(:),style),interp1(xp,yp,xi(:),style)]); | |
512 %!assert (interp1(xp,yp,xi,style),... | |
513 %! interp1(fliplr(xp),fliplr(yp),xi,style),100*eps); | |
514 %!assert (ppval(interp1(xp,yp,style,"pp"),xi), | |
515 %! interp1(xp,yp,xi,style,"extrap"),10*eps); | |
516 %!error interp1(1,1,1, style); | |
517 %!assert (interp1(xp,[yp',yp'],xi,style), | |
518 %! interp1(xp,[yp',yp'],xi,["*",style]),100*eps); | |
519 %!test style=['*',style]; | |
520 %!assert (interp1(xp, yp, [min(xp)-1, max(xp)+1],style), [NaN, NaN]); | |
521 %!assert (interp1(xp,yp,xp,style), yp, 100*eps); | |
522 %!assert (interp1(xp,yp,xp',style), yp', 100*eps); | |
523 %!assert (interp1(xp',yp',xp',style), yp', 100*eps); | |
524 %!assert (interp1(xp',yp',xp,style), yp, 100*eps); | |
525 %!assert (isempty(interp1(xp',yp',[],style))); | |
526 %!assert (isempty(interp1(xp,yp,[],style))); | |
527 %!assert (interp1(xp,[yp',yp'],xi(:),style),... | |
528 %! [interp1(xp,yp,xi(:),style),interp1(xp,yp,xi(:),style)]); | |
529 %!assert (interp1(xp,yp,xi,style),... | |
530 %! interp1(fliplr(xp),fliplr(yp),xi,style),100*eps); | |
531 %!assert (ppval(interp1(xp,yp,style,"pp"),xi), | |
532 %! interp1(xp,yp,xi,style,"extrap"),10*eps); | |
533 %!error interp1(1,1,1, style); | |
534 ## ENDBLOCK | |
535 ## ENDBLOCKTEST | |
402 | 536 |
403 %!# test linear extrapolation | 537 %!# test linear extrapolation |
404 %!assert (interp1([1:5],[3:2:11],[0,6],"linear","extrap"), [1, 13], eps); | 538 %!assert (interp1([1:5],[3:2:11],[0,6],"linear","extrap"), [1, 13], eps); |
405 %!assert (interp1(xp, yp, [-1, max(xp)+1],"linear",5), [5, 5]); | 539 %!assert (interp1(xp, yp, [-1, max(xp)+1],"linear",5), [5, 5]); |
406 | 540 |
407 %!error interp1 | 541 %!error interp1 |
408 %!error interp1(1:2,1:2,1,"bogus") | 542 %!error interp1(1:2,1:2,1,"bogus") |
409 | 543 |
410 %!error interp1(1,1,1, "nearest"); | |
411 %!assert (interp1(1:2,1:2,1.4,"nearest"),1); | 544 %!assert (interp1(1:2,1:2,1.4,"nearest"),1); |
412 %!error interp1(1,1,1, "linear"); | 545 %!error interp1(1,1,1, "linear"); |
413 %!assert (interp1(1:2,1:2,1.4,"linear"),1.4); | 546 %!assert (interp1(1:2,1:2,1.4,"linear"),1.4); |
414 %!error interp1(1:3,1:3,1, "cubic"); | 547 %!error interp1(1:3,1:3,1, "cubic"); |
415 %!assert (interp1(1:4,1:4,1.4,"cubic"),1.4); | 548 %!assert (interp1(1:4,1:4,1.4,"cubic"),1.4); |
422 %!assert (interp1(1:2:4,1:2:4,[0,1,1.4,3,4],"*linear"),[NaN,1,1.4,3,NaN]); | 555 %!assert (interp1(1:2:4,1:2:4,[0,1,1.4,3,4],"*linear"),[NaN,1,1.4,3,NaN]); |
423 %!error interp1(1:3,1:3,1, "*cubic"); | 556 %!error interp1(1:3,1:3,1, "*cubic"); |
424 %!assert (interp1(1:2:8,1:2:8,1.4,"*cubic"),1.4); | 557 %!assert (interp1(1:2:8,1:2:8,1.4,"*cubic"),1.4); |
425 %!error interp1(1:2,1:2,1, "*spline"); | 558 %!error interp1(1:2,1:2,1, "*spline"); |
426 %!assert (interp1(1:2:6,1:2:6,1.4,"*spline"),1.4); | 559 %!assert (interp1(1:2:6,1:2:6,1.4,"*spline"),1.4); |
427 | |
428 %!assert (ppval(interp1(xp,yp,"nearest","pp"),xi), | |
429 %! interp1(xp,yp,xi,"nearest","extrap"),10*eps); | |
430 %!assert (ppval(interp1(xp,yp,"linear","pp"),xi), | |
431 %! interp1(xp,yp,xi,"linear","extrap"),10*eps); | |
432 %!assert (ppval(interp1(xp,yp,"cubic","pp"),xi), | |
433 %! interp1(xp,yp,xi,"cubic","extrap"),10*eps); | |
434 %!assert (ppval(interp1(xp,yp,"pchip","pp"),xi), | |
435 %! interp1(xp,yp,xi,"pchip","extrap"),10*eps); | |
436 %!assert (ppval(interp1(xp,yp,"spline","pp"),xi), | |
437 %! interp1(xp,yp,xi,"spline","extrap"),10*eps); | |
438 | |
439 %!assert (ppval(interp1(xp,yp,"*nearest","pp"),xi), | |
440 %! interp1(xp,yp,xi,"*nearest","extrap"),10*eps); | |
441 %!assert (ppval(interp1(xp,yp,"*linear","pp"),xi), | |
442 %! interp1(xp,yp,xi,"*linear","extrap"),10*eps); | |
443 %!assert (ppval(interp1(xp,yp,"*cubic","pp"),xi), | |
444 %! interp1(xp,yp,xi,"*cubic","extrap"),10*eps); | |
445 %!assert (ppval(interp1(xp,yp,"*pchip","pp"),xi), | |
446 %! interp1(xp,yp,xi,"*pchip","extrap"),10*eps); | |
447 %!assert (ppval(interp1(xp,yp,"*spline","pp"),xi), | |
448 %! interp1(xp,yp,xi,"*spline","extrap"),10*eps); |