Mercurial > hg > octave-lyh
comparison scripts/general/interp1.m @ 6702:b2391d403ed2
[project @ 2007-06-12 21:39:26 by dbateman]
author | dbateman |
---|---|
date | Tue, 12 Jun 2007 21:39:27 +0000 |
parents | 419017274c1e |
children | 01036667884a |
comparison
equal
deleted
inserted
replaced
6701:3933e0693fe0 | 6702:b2391d403ed2 |
---|---|
68 ## xp=[0:10]; yp = sin(2*pi*xp/5); | 68 ## xp=[0:10]; yp = sin(2*pi*xp/5); |
69 ## lin=interp1(xp,yp,xf); | 69 ## lin=interp1(xp,yp,xf); |
70 ## spl=interp1(xp,yp,xf,'spline'); | 70 ## spl=interp1(xp,yp,xf,'spline'); |
71 ## cub=interp1(xp,yp,xf,'cubic'); | 71 ## cub=interp1(xp,yp,xf,'cubic'); |
72 ## near=interp1(xp,yp,xf,'nearest'); | 72 ## near=interp1(xp,yp,xf,'nearest'); |
73 ## plot(xf,yf,';original;',xf,lin,';linear;',xf,spl,';spline;',... | 73 ## plot(xf,yf,"r",xf,lin,"g",xf,spl,"b", ... |
74 ## xf,cub,';cubic;',xf,near,';nearest;',xp,yp,'*;;'); | 74 ## xf,cub,"c",xf,near,"m",xp,yp,"r*"); |
75 ## legend ("original","linear","spline","cubic","nearest") | |
75 ## @end group | 76 ## @end group |
76 ## @end example | 77 ## @end example |
77 ## | 78 ## |
78 ## @seealso{interpft} | 79 ## @seealso{interpft} |
79 ## @end deftypefn | 80 ## @end deftypefn |
325 %! xp=0:10; yp = sin(2*pi*xp/5); | 326 %! xp=0:10; yp = sin(2*pi*xp/5); |
326 %! lin=interp1(xp,yp,xf,"linear"); | 327 %! lin=interp1(xp,yp,xf,"linear"); |
327 %! spl=interp1(xp,yp,xf,"spline"); | 328 %! spl=interp1(xp,yp,xf,"spline"); |
328 %! cub=interp1(xp,yp,xf,"pchip"); | 329 %! cub=interp1(xp,yp,xf,"pchip"); |
329 %! near=interp1(xp,yp,xf,"nearest"); | 330 %! near=interp1(xp,yp,xf,"nearest"); |
330 %! plot(xf,yf,";original;",xf,near,";nearest;",xf,lin,";linear;",... | 331 %! plot(xf,yf,"r",xf,near,"g",xf,lin,"b",xf,cub,"c",xf,spl,"m",xp,yp,"r*"); |
331 %! xf,cub,";pchip;",xf,spl,";spline;",xp,yp,"*;;"); | 332 %! legend ("original","nearest","linear","pchip","spline") |
332 %! %-------------------------------------------------------- | 333 %! %-------------------------------------------------------- |
333 %! % confirm that interpolated function matches the original | 334 %! % confirm that interpolated function matches the original |
334 | 335 |
335 %!demo | 336 %!demo |
336 %! xf=0:0.05:10; yf = sin(2*pi*xf/5); | 337 %! xf=0:0.05:10; yf = sin(2*pi*xf/5); |
337 %! xp=0:10; yp = sin(2*pi*xp/5); | 338 %! xp=0:10; yp = sin(2*pi*xp/5); |
338 %! lin=interp1(xp,yp,xf,"*linear"); | 339 %! lin=interp1(xp,yp,xf,"*linear"); |
339 %! spl=interp1(xp,yp,xf,"*spline"); | 340 %! spl=interp1(xp,yp,xf,"*spline"); |
340 %! cub=interp1(xp,yp,xf,"*cubic"); | 341 %! cub=interp1(xp,yp,xf,"*cubic"); |
341 %! near=interp1(xp,yp,xf,"*nearest"); | 342 %! near=interp1(xp,yp,xf,"*nearest"); |
342 %! plot(xf,yf,";*original;",xf,near,";*nearest;",xf,lin,";*linear;",... | 343 %! plot(xf,yf,"r",xf,near,"g",xf,lin,"b",xf,cub,"c",xf,spl,"m",xp,yp,"r*"); |
343 %! xf,cub,";*cubic;",xf,spl,";*spline;",xp,yp,"*;;"); | 344 %! legend ("*original","*nearest","*linear","*cubic","*spline") |
344 %! %-------------------------------------------------------- | 345 %! %-------------------------------------------------------- |
345 %! % confirm that interpolated function matches the original | 346 %! % confirm that interpolated function matches the original |
346 | 347 |
347 ## For each type of interpolated test, confirm that the interpolated | 348 ## For each type of interpolated test, confirm that the interpolated |
348 ## value at the knots match the values at the knots. Points away | 349 ## value at the knots match the values at the knots. Points away |