Google Groups no longer supports new Usenet posts or subscriptions. Historical content remains viewable.
Dismiss

Using griddata with method 'v4'

645 views
Skip to first unread message

Daniel Drori

unread,
May 3, 2009, 11:59:01 AM5/3/09
to
Hi there,

I'm working on a project and I need to build a 3d surface by giving the coordinates: x,y,z. I use the following code:

PictureSize = size(A);
ty = 1:1:PictureSize (1);
tx = 1:1:PictureSize (2);
[X,Y] = meshgrid(tx,ty);
Z = griddata(x,y,z, X, Y,'v4');
surf(X,Y,Z);

I tried to use the method 'cubic' instead of 'v4' but it gives me a lot of NaN's, and when I start using the method 'v4' I start getting real values.
I have several questions:

1) What are the differences between the two methods 'cubic' and 'v4'??
2) Where can I read about the method 'v4' in order to know how it works?
3) Is there any way I can translate the 'griddata' function with the method 'v4' to C++?

Please help me...
Thanx in advance
Daniel Drori
dan...@tehila.gov.il

Daniel Drori

unread,
May 3, 2009, 12:08:02 PM5/3/09
to
...

Bruno Luong

unread,
May 3, 2009, 12:21:01 PM5/3/09
to
"Daniel Drori" <daniel...@gmail.com> wrote in message <gtkf05$cuc$1...@fred.mathworks.com>...

> 2) Where can I read about the method 'v4' in order to know how it works?

According to the doc, v3 method is derived here:

[2] Sandwell, David T., "Biharmonic Spline Interpolation of GEOS-3 and SEASAT Altimeter Data", Geophysical Research Letters, 14, 2, 139&#8211;142,1987.

"Seasat" altimeter data is the sea surface height (SSH) data acquired by the a satellite called SEASAT; -)

Bruno

John D'Errico

unread,
May 3, 2009, 6:57:01 PM5/3/09
to
"Daniel Drori" <daniel...@gmail.com> wrote in message <gtkf05$cuc$1...@fred.mathworks.com>...
> Hi there,
>
> I'm working on a project and I need to build a 3d surface by giving the coordinates: x,y,z. I use the following code:
>
> PictureSize = size(A);
> ty = 1:1:PictureSize (1);
> tx = 1:1:PictureSize (2);
> [X,Y] = meshgrid(tx,ty);
> Z = griddata(x,y,z, X, Y,'v4');
> surf(X,Y,Z);
>
> I tried to use the method 'cubic' instead of 'v4' but it gives me a lot of NaN's, and when I start using the method 'v4' I start getting real values.
> I have several questions:
>
> 1) What are the differences between the two methods 'cubic' and 'v4'??

'cubic' is a triangulation based method. So if a point
is outside the convex hull of the data, then you won't
find a triangle that contains it. Therefore ... NaN.

'v4' is apparently a Greens' function approach. It uses
a full matrix composed of ALL of the interpoint
distances. This will be SLOW for many points, and
extremely memory intensive.


> 2) Where can I read about the method 'v4' in order to know how it works?
> 3) Is there any way I can translate the 'griddata' function with the method 'v4' to C++?
>

Just pick any radial basis function method. There
are many of them to be found. In fact, there are
RBF codes on the file exchange.

These RBF methods are not always terribly good.
I originally played with them for a year or so,
before developing the ideas behind gridfit, which
works FAR better on the problems I've ever seen,
as well as giving you more control over the results.

John

Daniel Drori

unread,
May 27, 2009, 7:49:01 AM5/27/09
to

hi John,
concerning my questions:


1) What are the differences between the two methods 'cubic' and 'v4'??

2) Where can I read about the method 'v4' in order to know how it works?

are there any researches so I can read them?
why do I get negative values when I use V4?
is there any way to get Nan's with v4? why?
basically, all I need to know is how dose this method calculate the 3d surface i get..

thanx in advance
Daniel

John D'Errico

unread,
May 27, 2009, 9:46:01 AM5/27/09
to
"Daniel Drori" <daniel...@gmail.com> wrote in message <gvj9bd$mda$1...@fred.mathworks.com>...

> hi John,
> concerning my questions:
> 1) What are the differences between the two methods 'cubic' and 'v4'??

Think of the 'cubic' method as a version of a spline,
on a triangular support. So you will have cubic
pieces in 2 dimensions. I'd expect to see derivative
breaks of some order across the triangle boundaries.

The 'v4' method is much like a radial basis function
interpolant. These methods are distance based
methods, so you will have a single radially symmetric
basis function around EVERY data point. The 'v4'
method will form a linear combination of these basis
functions, so it must formulate and solve a linear
system of equations, of size the number of data
points.

> 2) Where can I read about the method 'v4' in order to know how it works?
> are there any researches so I can read them?

There are many such interpolants, multi-quadric and
inverse multi-quadric. Read Richard Franke's paper
on this subject (Mathematics of Computation) for
a good discussion of

R. Franke, "Scattered Data Interpolation: Tests of Some
Methods", Mathematics of Computation, 1982


> why do I get negative values when I use V4?

It has no constraint on the value it predicts, merely
interpolating your data. However, locations between
the data points and exterior to them may take on
any value that is consistent with the interpolant used.
Any polynomial interpolant has similar behaviors.

The 'v4' method is a poor choice in general, IMHO.
It is slow. It will do nasty things to you in extrapolation,
as well as in "intrapolation". (Intrapolation is a word
of mine that describes interpolation across a large
internal hole in your data. This can have many of the
bad characteristics of extrapolation.)


> is there any way to get Nan's with v4? why?

Not unless you have NaNs in the data iself, or possibly,
replicate data points. As described above, 'v4' is a
distance based method that solves a linear system of
equations for the solution. NaNs will occur only if
there are already NaNs in the data, or if there are
replicate points in your set. The latter case will
generate a singular system, so might introduce NaNs
in the solution.

The other methods of griddata introduce NaNs because
they are triangulation based. Points outside of the convex
hull will cause failure here, so NaNs are returned.

John

Steven Lord

unread,
May 27, 2009, 9:56:51 AM5/27/09
to

"Daniel Drori" <daniel...@gmail.com> wrote in message
news:gvj9bd$mda$1...@fred.mathworks.com...

*snip*

> 2) Where can I read about the method 'v4' in order to know how it works?

Take a look at the Algorithm and References sections of the function
reference page:

http://www.mathworks.com/access/helpdesk/help/techdoc/ref/griddata.html

It gives the journal article that describes the 'v4' method. I'm guessing
your local library may have this journal or may be able to get a copy of
that article for you.

--
Steve Lord
sl...@mathworks.com


Bruno Luong

unread,
May 28, 2009, 3:40:17 PM5/28/09
to
A question to John:

- I have a program where I use griddata v4 from scatter to scatter with extrapolation.The interpolation/extrapolation is used for visualization purpose. I would like to try GRIDFIT. But this function seems to require a gridded target nodes. What is the reason for that? Can I trick it by calling gridfit many times as there are scattered target points and still get a coherence surface?

Bruno

Joaquim Luis

unread,
May 28, 2009, 4:09:02 PM5/28/09
to

> is there any way to get Nan's with v4? why?
> basically, all I need to know is how dose this method calculate the 3d surface i get..
>
> thanx in advance
> Daniel

Mirone has MEX files for both the GMT's "surface" program and the MB-SYSTEM equivalent (surface_m.c & gmtmbgrid_m.c). The both use the minimum curvature algorithm that is very fast and since they are MEXs user is not obliged to provide an entire full matrix for X, and Y which a find a absurd and highly limits (due to memory issues) the size of the grid one may compute. The gmtmbgrid_m computes NaNs on cells not constrained by data (controlled by an input option -C).

J. Luis

John D'Errico

unread,
May 28, 2009, 5:04:02 PM5/28/09
to
"Bruno Luong" <b.l...@fogale.findmycountry> wrote in message <gvmpb1$ln1$1...@fred.mathworks.com>...

> A question to John:
>
> - I have a program where I use griddata v4 from scatter to scatter with extrapolation.The interpolation/extrapolation is used for visualization purpose. I would like to try GRIDFIT. But this function seems to require a gridded target nodes. What is the reason for that? Can I trick it by calling gridfit many times as there are scattered target points and still get a coherence surface?
>
> Bruno

Hi Bruno,

Gridfit builds a plaid grid for a few reasons. This makes it
efficient for relatively large grids, since I can build a simple
style of regularizer easily. It is also trivial to build the
predictor array. Finally, it makes for a relatively simple
interface that can be used simply out of the box.

I have written a gridfit style code that does not require
a plaid grid. It works on a triangulated domain, and even
does so in n-dimensions. It is a little slower to build the
matrices though than gridfit, but since it will generally
work on smaller problems, the two should cancel out.

I've not really spent any serious time in optimizing it.
One thing I did do was to write a tool based on it that
does adaptive mesh refinement. So I can start with a
coarse triangulation of a domain, refining the regions
of the domain where there is significant lack of fit.

So this is the tool I'd recommend you play with here,
not gridfit.

John

Bruno Luong

unread,
May 28, 2009, 5:22:01 PM5/28/09
to
Thank you John. Your opinion is informative as always.

Bruno

John D'Errico

unread,
May 28, 2009, 5:39:02 PM5/28/09
to
"Bruno Luong" <b.l...@fogale.findmycountry> wrote in message <gvmv9p$sb$1...@fred.mathworks.com>...

> Thank you John. Your opinion is informative as always.
>
> Bruno

I'll send it to you if you wish to try it out.

Let me know.

John

Bruno Luong

unread,
May 29, 2009, 2:49:02 AM5/29/09
to
Thank you John. Right now I'm using the 'v4'. I have to finalize the code soon for delivery, no time to play with other methods. I'll be happy to contact you later to test the scattered interpolation code.

Cheers,

Bruno

Neema

unread,
Jan 1, 2012, 7:32:08 PM1/1/12
to
"John D'Errico" <wood...@rochester.rr.com> wrote in message <gvmu82$kin$1...@fred.mathworks.com>...
John,

It would be very useful if you can post that version of gridfit that works on triangulated domains. Now it is quite a while from this message but you still didn't include it in the file exchange distribution.

Thanks in advance

Peter Mao

unread,
May 8, 2013, 2:28:09 PM5/8/13
to
"John D'Errico" <wood...@rochester.rr.com> wrote in message <gvjg6p$fbb$1...@fred.mathworks.com>...
...
> The 'v4' method is a poor choice in general, IMHO.
> It is slow. It will do nasty things to you in extrapolation,
> as well as in "intrapolation". (Intrapolation is a word
> of mine that describes interpolation across a large
> internal hole in your data. This can have many of the
> bad characteristics of extrapolation.)

Hi John,

my experience with 'v4' (based on Sandwell, 1987) doesn't exactly conform to what you're saying here. Indeed, it is slow, but I found that it handled "intrapolation" better than the other interpolation methods available in Matlab (I checked out 'nearest', 'linear' and 'cubic (spline)').

I can post up specifics, if you're interested in discussing this further.

Also, to expand on the topic of interpolation methods in 2D, do you have any insight on Shepard's method (Shepard, ACM, 1968) or the triangular interpolation method of Cline and Renka (1984)? Those are scattered-data 2D interpolation methods in NAG that I haven't seen in Matlab (maybe in the File Exchange?).

Peter

John D'Errico

unread,
May 8, 2013, 4:17:16 PM5/8/13
to
"Peter Mao" wrote in message <kme5fp$fgb$1...@newscl01ah.mathworks.com>...
Peter, I won't argue with you. Feel free to use it or not.

My comments stand. Period. Beyond that, I am retired
and will not re-enter a conversation from years ago.

John
0 new messages