From: fra on
Hi,
I just start to usse Matlab now: I have to interpolate max e min of a
transmission spectrum and spline function doesn't work very well. I
tried to use pchip just follow the example I found in ML inserting my
value but I got errors:


??? Error using ==> polyfun\private\chckxy
There should be at least two data points.

Error in ==> pchip at 59
[x,y,sizey] = chckxy(x,y);

Error in ==> max at 4
p=pchip(x,y,t);

this is my m-file:
x=462, 502,554,620,706,820,996,1232,1630;
y=0.86508,0.88793,0.90232,0.90999,0.91909,0.93151,0.93536,0.93856,0.93942;
t=462:2:1630;
p=pchip(x,y,t);
plot(x,y,'o',t,p,'-',t);
legend('data', 'pchip', 4)

From: John D'Errico on
fra wrote:
>
>
> Hi,
> I just start to usse Matlab now: I have to interpolate max e min of
> a
> transmission spectrum and spline function doesn't work very well. I
> tried to use pchip just follow the example I found in ML inserting
> my
> value but I got errors:
>
>
> ??? Error using ==> polyfun\private\chckxy
> There should be at least two data points.
>
> Error in ==> pchip at 59
> [x,y,sizey] = chckxy(x,y);
>
> Error in ==> max at 4
> p=pchip(x,y,t);
>
> this is my m-file:
> x=462, 502,554,620,706,820,996,1232,1630;
>
y=0.86508,0.88793,0.90232,0.90999,0.91909,0.93151,0.93536,0.93856,0.
> 93942;
> t=462:2:1630;
> p=pchip(x,y,t);
> plot(x,y,'o',t,p,'-',t);
> legend('data', 'pchip', 4)

No. Splines are not always a good
choice for interpolating spectra.
They do nasty things - predicting
negative values and introducing
oscillations where none belong.

Sometimes a better choice is to
work in the log domain. Thus, log
your spectra, then interpolate
and exponentiate the result. This
often makes more sense.

Pchip does work, if used properly.
You could also have used interp1,
with the pchip option.

x=[462, 502,554,620,706,820,996,1232,1630];
y=[0.86508,0.88793,0.90232,0.90999,0.91909,0.93151,0.93536,0.93856,0.9
3942];
t=462:2:1630;
splp=pchip(x,y);
p = ppval(splp,t);

spls=spline(x,y);
s = ppval(spls,t);

plot(x,y,'o',t,p,'r-',t,s,'g--');
legend('data', 'pchip', 'spline', 4)

HTH,
John D'Errico