Thread Subject: Interpolation

Subject: Interpolation

From: Travis

Date: 5 May, 2009 16:12:02

Message: 1 of 17

I have some data that I want to smooth out in three dimensions. I have tried interp2 with the spline method, and it changes the original data. I have tried interp1 on each row of data with cubic and spline and it too changes the original data.

Is there any interpolation command, other than linear, that does not use the not-a-knotcondition?

Subject: Interpolation

From: John D'Errico

Date: 5 May, 2009 17:47:01

Message: 2 of 17

"Travis" <sinusoid2@hotmail.com> wrote in message <gtpogi$ncc$1@fred.mathworks.com>...
> I have some data that I want to smooth out in three dimensions. I have tried interp2 with the spline method, and it changes the original data. I have tried interp1 on each row of data with cubic and spline and it too changes the original data.
>
> Is there any interpolation command, other than linear, that does not use the not-a-knotcondition?

Neither interp2 or interp1 will change the data.
They are interpolants. Please explain why you
believe they have changed the data. I am quite
confident I will show you to be incorrect.

The not-a-knot end conditions do not change
the data.

John

Subject: Interpolation

From: Travis

Date: 5 May, 2009 18:56:02

Message: 3 of 17

"John D'Errico" <woodchips@rochester.rr.com> wrote in message <gtpu2l$gm3$1@fred.mathworks.com>...
> "Travis" <sinusoid2@hotmail.com> wrote in message <gtpogi$ncc$1@fred.mathworks.com>...
> > I have some data that I want to smooth out in three dimensions. I have tried interp2 with the spline method, and it changes the original data. I have tried interp1 on each row of data with cubic and spline and it too changes the original data.
> >
> > Is there any interpolation command, other than linear, that does not use the not-a-knotcondition?
>
> Neither interp2 or interp1 will change the data.
> They are interpolants. Please explain why you
> believe they have changed the data. I am quite
> confident I will show you to be incorrect.
>
> The not-a-knot end conditions do not change
> the data.
>
> John

Here are images before and after interpolation using the following code to go from Temp to Temp2

h = 6:1:30;
g = -6:.25:0;
Temp2 = interp2(dist,depth,temp,h,g','spline')

http://img10.imageshack.us/gal.php?g=temp2c.jpg

Original data is on the right, interp'd is on the left. The point with the info is a hard data point that needs to be preserved.

Subject: Interpolation

From: Travis

Date: 18 May, 2009 15:09:02

Message: 4 of 17

"John D'Errico" <woodchips@rochester.rr.com> wrote in message <gtpu2l$gm3$1@fred.mathworks.com>...
> "Travis" <sinusoid2@hotmail.com> wrote in message <gtpogi$ncc$1@fred.mathworks.com>...
> > I have some data that I want to smooth out in three dimensions. I have tried interp2 with the spline method, and it changes the original data. I have tried interp1 on each row of data with cubic and spline and it too changes the original data.
> >
> > Is there any interpolation command, other than linear, that does not use the not-a-knotcondition?
>
> Neither interp2 or interp1 will change the data.
> They are interpolants. Please explain why you
> believe they have changed the data. I am quite
> confident I will show you to be incorrect.
>
> The not-a-knot end conditions do not change
> the data.
>
> John

Any help on this? I still have not been able to fix it.

Subject: Interpolation

From: Travis

Date: 11 Jun, 2009 22:20:18

Message: 5 of 17

So it looks like interp2 does not keep the datapoints when the next data point is NaN. Does anyone know a way to change this?

Subject: Interpolation

From: John D'Errico

Date: 12 Jun, 2009 01:18:01

Message: 6 of 17

"Travis" <sinusoid2@hotmail.com> wrote in message <gtq242$mue$1@fred.mathworks.com>...
> "John D'Errico" <woodchips@rochester.rr.com> wrote in message <gtpu2l$gm3$1@fred.mathworks.com>...
> > "Travis" <sinusoid2@hotmail.com> wrote in message <gtpogi$ncc$1@fred.mathworks.com>...
> > > I have some data that I want to smooth out in three dimensions. I have tried interp2 with the spline method, and it changes the original data. I have tried interp1 on each row of data with cubic and spline and it too changes the original data.
> > >
> > > Is there any interpolation command, other than linear, that does not use the not-a-knotcondition?
> >
> > Neither interp2 or interp1 will change the data.
> > They are interpolants. Please explain why you
> > believe they have changed the data. I am quite
> > confident I will show you to be incorrect.
> >
> > The not-a-knot end conditions do not change
> > the data.
> >
> > John
>
> Here are images before and after interpolation using the following code to go from Temp to Temp2
>
> h = 6:1:30;
> g = -6:.25:0;
> Temp2 = interp2(dist,depth,temp,h,g','spline')
>
> http://img10.imageshack.us/gal.php?g=temp2c.jpg
>
> Original data is on the right, interp'd is on the left. The point with the info is a hard data point that needs to be preserved.

I missed this response.

Your data to be interpolated is not really a complete
plaid grid. There are holes in it around the edge, with
empty data. As you point out these elements are NaNs,
so you are extrapolating with interp2. Worse, you are
trying to use the spline interpolant, which is unable
to deal with this non-simple domain. The spline method
is a tensor product interpolant, but your domain is not
of that form given the nans. Interp2 is inappropriate
for this task.

You must choose another scheme, that can deal with
what is essentially scattered data. Griddata could do
so. You must decide what will be done in the corners.
Passing in NaNs will not work for almost any method.
Pass in only the actual data.

John

Subject: Interpolation

From: Travis

Date: 12 Jun, 2009 02:02:01

Message: 7 of 17

"John D'Errico" <woodchips@rochester.rr.com> wrote in message <h0sac9$5cn$1@fred.mathworks.com>...
> "Travis" <sinusoid2@hotmail.com> wrote in message <gtq242$mue$1@fred.mathworks.com>...
> > "John D'Errico" <woodchips@rochester.rr.com> wrote in message <gtpu2l$gm3$1@fred.mathworks.com>...
> > > "Travis" <sinusoid2@hotmail.com> wrote in message <gtpogi$ncc$1@fred.mathworks.com>...
> > > > I have some data that I want to smooth out in three dimensions. I have tried interp2 with the spline method, and it changes the original data. I have tried interp1 on each row of data with cubic and spline and it too changes the original data.
> > > >
> > > > Is there any interpolation command, other than linear, that does not use the not-a-knotcondition?
> > >
> > > Neither interp2 or interp1 will change the data.
> > > They are interpolants. Please explain why you
> > > believe they have changed the data. I am quite
> > > confident I will show you to be incorrect.
> > >
> > > The not-a-knot end conditions do not change
> > > the data.
> > >
> > > John
> >
> > Here are images before and after interpolation using the following code to go from Temp to Temp2
> >
> > h = 6:1:30;
> > g = -6:.25:0;
> > Temp2 = interp2(dist,depth,temp,h,g','spline')
> >
> > http://img10.imageshack.us/gal.php?g=temp2c.jpg
> >
> > Original data is on the right, interp'd is on the left. The point with the info is a hard data point that needs to be preserved.
>
> I missed this response.
>
> Your data to be interpolated is not really a complete
> plaid grid. There are holes in it around the edge, with
> empty data. As you point out these elements are NaNs,
> so you are extrapolating with interp2. Worse, you are
> trying to use the spline interpolant, which is unable
> to deal with this non-simple domain. The spline method
> is a tensor product interpolant, but your domain is not
> of that form given the nans. Interp2 is inappropriate
> for this task.
>
> You must choose another scheme, that can deal with
> what is essentially scattered data. Griddata could do
> so. You must decide what will be done in the corners.
> Passing in NaNs will not work for almost any method.
> Pass in only the actual data.
>
> John

I tried griddata and while it didn't mess up at the NaN's it did cut off all data that bordered them, and did a great job on the rest of it.

Subject: Interpolation

From: John D'Errico

Date: 12 Jun, 2009 02:19:02

Message: 8 of 17

"Travis " <sinusoid2@hotmail.com> wrote in message <h0scup$i72$1@fred.mathworks.com>...

> I tried griddata and while it didn't mess up at the NaN's it did cut off all data that bordered them, and did a great job on the rest of it.

So you wish to extrapolate into the corners?

Griddata can do this, IF you use the 'v4' method.

John

Subject: Interpolation

From: Travis

Date: 12 Jun, 2009 03:22:01

Message: 9 of 17

"John D'Errico" <woodchips@rochester.rr.com> wrote in message <h0sdum$lbv$1@fred.mathworks.com>...
> "Travis " <sinusoid2@hotmail.com> wrote in message <h0scup$i72$1@fred.mathworks.com>...
>
> > I tried griddata and while it didn't mess up at the NaN's it did cut off all data that bordered them, and did a great job on the rest of it.
>
> So you wish to extrapolate into the corners?
>
> Griddata can do this, IF you use the 'v4' method.
>
> John

I just want to smooth the data out so it is not angular, while keeping the original data points, and the original NaN's.

Subject: Interpolation

From: Bruno Luong

Date: 12 Jun, 2009 05:46:02

Message: 10 of 17

"Travis " <sinusoid2@hotmail.com> wrote in message <h0shkp$grg$1@fred.mathworks.com>...
> "John D'Errico" <woodchips@rochester.rr.com> wrote in message <h0sdum$lbv$1@fred.mathworks.com>...
> > "Travis " <sinusoid2@hotmail.com> wrote in message <h0scup$i72$1@fred.mathworks.com>...
> >
> > > I tried griddata and while it didn't mess up at the NaN's it did cut off all data that bordered them, and did a great job on the rest of it.
> >
> > So you wish to extrapolate into the corners?
> >
> > Griddata can do this, IF you use the 'v4' method.
> >
> > John
>
> I just want to smooth the data out so it is not angular, while keeping the original data points, and the original NaN's.

Start to call 'v4' as John suggested, then replace the filled fine data with NaN where the location of the coarse data is NaN. I have coded something along this line for you previously Travis IIRC, just replace SPLINE by INTERP2 with V4 option.

Bruno

Subject: Interpolation

From: Travis

Date: 22 Jun, 2009 17:06:01

Message: 11 of 17

"Bruno Luong" <b.luong@fogale.findmycountry> wrote in message <h0sq2p$b8o$1@fred.mathworks.com>...
> "Travis " <sinusoid2@hotmail.com> wrote in message <h0shkp$grg$1@fred.mathworks.com>...
> > "John D'Errico" <woodchips@rochester.rr.com> wrote in message <h0sdum$lbv$1@fred.mathworks.com>...
> > > "Travis " <sinusoid2@hotmail.com> wrote in message <h0scup$i72$1@fred.mathworks.com>...
> > >
> > > > I tried griddata and while it didn't mess up at the NaN's it did cut off all data that bordered them, and did a great job on the rest of it.
> > >
> > > So you wish to extrapolate into the corners?
> > >
> > > Griddata can do this, IF you use the 'v4' method.
> > >
> > > John
> >
> > I just want to smooth the data out so it is not angular, while keeping the original data points, and the original NaN's.
>
> Start to call 'v4' as John suggested, then replace the filled fine data with NaN where the location of the coarse data is NaN. I have coded something along this line for you previously Travis IIRC, just replace SPLINE by INTERP2 with V4 option.
>
> Bruno

Using the 'V4' method just puts the whole grid to NaN.

Subject: Interpolation

From: Travis

Date: 3 Sep, 2009 22:33:20

Message: 12 of 17

Does anyone have any other ideas on how to force MATLAB to preserve the original datum points during interpolation?

Subject: Interpolation

From: dpb

Date: 6 Oct, 2009 22:47:37

Message: 13 of 17

Travis wrote:
> Does anyone have any other ideas on how to force MATLAB to preserve
> the original datum points during interpolation?

I'm unaware that it won't automagically do so...demonstration of problem????

--

Subject: Interpolation

From: Travis

Date: 26 Oct, 2009 15:43:03

Message: 14 of 17


http://img10.imageshack.us/gal.php?g=temp2c.jpg

This shows before and after pictures.

 

Subject: Interpolation

From: dpb

Date: 9 Feb, 2010 15:45:16

Message: 15 of 17

Travis wrote:
> http://img10.imageshack.us/gal.php?g=temp2c.jpg
>
> This shows before and after pictures.

Not of much help w/o code that demonstrates what you did and explanation
of what you think went wrong and what you expected to happen.

BTW, my previous response was predicated on the interpolating
vector/surface having the original points in it as well as the desired
interpolated points. The various interpX functions return values for
the input vectors/surfaces; if you don't have points at the value of the
interpolating function in the requested interpolated return
vector/surface there won't be values returned there (unless choose
'nearest' option or some such other special case).

--

Subject: Interpolation

From: Travis

Date: 19 Feb, 2010 19:21:05

Message: 16 of 17

OK here are the variables used.

temp = 29.6 29.4 28.5 28.1 28.5
25.3 23.7 23.50 24.7 24.4
24.2 21.9 21.8 23.8 23.4
23.1 20.8 20.9 23 22.4
22.3 20.2 20.1 22.2 21.8
22 19.85 20.05 21.7 21.6
NaN 19.5 20 21.2 NaN
NaN 19.9 NaN NaN NaN

dist = 6 12 18 24 30
depth = 0
-1
-2
-3
-4
-4.50000000000000
-5
-6

Dist = min(dist):1:max(dist);
Depth = min(depth):0.5:max(depth)';
TEMP = interp2(dist,depth,temp,Dist,Depth,'spline');

The original data points are not always held.

Subject: Interpolation

From: dpb

Date: 19 Feb, 2010 20:25:32

Message: 17 of 17

Travis wrote:
> OK here are the variables used.

...[data elided for brevity]...

> Dist = min(dist):1:max(dist);
> Depth = min(depth):0.5:max(depth)';
> TEMP = interp2(dist,depth,temp,Dist,Depth,'spline');
>
> The original data points are not always held.

In my release the NaNs propogate thruout w/ the spline as submitted. I
didn't take time to pare down into the smaller region that would be
constrained.

Removing 'spline' does return the table values at the intermediate
points here.

I can only surmise the spline is least-squares rather than thru each
point perhaps. Doc's don't specify in my version/release what is used.
  Might try some of the other choices if needed.

I wasn't thinking of other than linear, though, I realize.

--

Tags for this Thread

Everyone's Tags:

Add a New Tag:

Separated by commas
Ex.: root locus, bode

What are tags?

A tag is like a keyword or category label associated with each thread. Tags make it easier for you to find threads of interest.

Anyone can tag a thread. Tags are public and visible to everyone.

Tag Activity for This Thread
Tag Applied By Date/Time
interpolation Travis 5 May, 2009 12:14:03
rssFeed for this Thread

Contact us at files@mathworks.com