From: stephen on
Hi, I have a question about two-dimensional interpolation. I know in Matlab you could use interp2 to do the two dimensional interpolation. But you have to mesh grid before doing so. If I have a very large matrix (e.g. 500,000x3 [X Y Z]) and I want to interpolate from this large matrix. For example, interp2(X,Y,Z,x1,y1), or griddata(X,Y,Z,x1,y1)… Since the matrix is too big, it basically tells me out of memory. Does anyone know how to get the result out of this large matrix by using two dimensional interpolation?

Thanks for your help.

Stephen
From: Walter Roberson on
stephen wrote:
> Hi, I have a question about two-dimensional interpolation. I know in
> Matlab you could use interp2 to do the two dimensional interpolation.
> But you have to mesh grid before doing so. If I have a very large matrix
> (e.g. 500,000x3 [X Y Z]) and I want to interpolate from this large
> matrix. For example, interp2(X,Y,Z,x1,y1), or
> griddata(X,Y,Z,x1,y1)… Since the matrix is too big, it basically
> tells me out of memory. Does anyone know how to get the result out of
> this large matrix by using two dimensional interpolation?

[xsort, xidx]= sort(X);
[ysort, yidx] = sort(Y);

[xu, xuidx] = unique(xsort);
[yu, yuidx] = unique(ysort);

xn = interp1(xu, 1:length(xu), x1);
yn = interp1(yu, 1:length(yu), y1);

Now match each xn positionally with the corresponding xuidx, which will in
turn tell you positionally where to look in xidx to find the first X "nearby"
the target x1. There might be other points with identical X: you want to know
those points too, and you want a few X "nearby".

Same logic for yn.

What you are developing for each x1 and y1 is a set of points in the original
grid that are close enough to the original point to influence the surface
shape. Now that take subset of points and interp2() over it to get your target
x1 and y1.

The initial sorting should be fast, building the per-point "patch of
influence" might not be all that efficient, but it shouldn't run out of memory.
From: stephen on
Walter Roberson <roberson(a)hushmail.com> wrote in message <i1ie8j$5k4$1(a)canopus.cc.umanitoba.ca>...
> stephen wrote:
> > Hi, I have a question about two-dimensional interpolation. I know in
> > Matlab you could use interp2 to do the two dimensional interpolation.
> > But you have to mesh grid before doing so. If I have a very large matrix
> > (e.g. 500,000x3 [X Y Z]) and I want to interpolate from this large
> > matrix. For example, interp2(X,Y,Z,x1,y1), or
> > griddata(X,Y,Z,x1,y1)&#8230; Since the matrix is too big, it basically
> > tells me out of memory. Does anyone know how to get the result out of
> > this large matrix by using two dimensional interpolation?
>
> [xsort, xidx]= sort(X);
> [ysort, yidx] = sort(Y);
>
> [xu, xuidx] = unique(xsort);
> [yu, yuidx] = unique(ysort);
>
> xn = interp1(xu, 1:length(xu), x1);
> yn = interp1(yu, 1:length(yu), y1);
>
> Now match each xn positionally with the corresponding xuidx, which will in
> turn tell you positionally where to look in xidx to find the first X "nearby"
> the target x1. There might be other points with identical X: you want to know
> those points too, and you want a few X "nearby".
>
> Same logic for yn.
>
> What you are developing for each x1 and y1 is a set of points in the original
> grid that are close enough to the original point to influence the surface
> shape. Now that take subset of points and interp2() over it to get your target
> x1 and y1.
>
> The initial sorting should be fast, building the per-point "patch of
> influence" might not be all that efficient, but it shouldn't run out of memory.

Thanks a lot for your response, Walter.

I still have a question though. After the X and Y were sorted, how did you find the corresponding Z? by looking at xidx and yidx?

Thanks,
Stephen