From: Justme on
Hey matlab community,
Question. I currently am using the interp1 function when interpolating data being read from a couple of files.

Everything seems to work fine accept when I am trying to print the graph values. The graph is printed out fine, able to output Min and Max. However, usually when I try to print out an average, I keep running into NANs. I've done several troubleshooting methods..the only thing I can really think of is that I am not using the interp1 function properly.

I've read that there is an 'extrap' function that takes into account NaNs? But I am unfamiliar as to how to use this. Shouldn't I just be able to say Function1 = interp1(data1,data1,data2,'extrap')? Does that makes sense?

Thanks for the help in advance

~GJ
From: TideMan on
On May 20, 6:00 am, "Justme " <sa...(a)aol.com> wrote:
> Hey matlab community,
>    Question.  I currently am using the interp1 function when interpolating data being read from a couple of files.  
>
> Everything seems to work fine accept when I am trying to print the graph values.  The graph is printed out fine, able to output Min and Max. However, usually when I try to print out an average, I keep running into NANs.   I've done several troubleshooting methods..the only thing I can really think of is that I am not using the interp1 function properly.
>
> I've read that there is an 'extrap' function that takes into account NaNs? But I am unfamiliar as to how to use this.  Shouldn't I just be able to say Function1 = interp1(data1,data1,data2,'extrap')? Does that makes sense?
>
> Thanks for the help in advance
>
> ~GJ

You use a very odd arguments in interp1 (the first two arguments are
usually different), but as it says in the help, for linear
interpolation you invoke extrapolation like this:
y=interp1(xin,yin,x,'linear','extrap');
Note that if you use splines or pchip, you don't need to specify
extrap.

A word of caution: linear extrapolation is very dangerous. It can
produce wildly wrong results. You say that you need to eliminate the
NaNs so that you can take a mean, but what will be the meaning of the
mean if you have included wildly wrong extrapolated points?
Why not just ignore the NaNs when calculating the mean?
igood=~isnan(y);
ybar=mean(y(igood));