Discover MakerZone

MATLAB and Simulink resources for Arduino, LEGO, and Raspberry Pi

Learn more

Discover what MATLAB® can do for your career.

Opportunities for recent engineering grads.

Apply Today

Thread Subject:
multi-object interpolate

Subject: multi-object interpolate

From: Ha

Date: 15 Nov, 2012 18:09:12

Message: 1 of 4


I don't know if the title is correct for my question. Below is a simple example to illustrate my problem.

x = -5:5;
y = -5:5;

[X Y] = meshgrid(x,y);

Z1 = [
7.1 6.4 5.8 5.4 5.1 5.0 5.1 5.4 5.8 6.4 7.1
6.4 5.7 5.0 4.5 4.1 4.0 4.1 4.5 5.0 5.7 6.4
5.8 5.0 4.2 3.6 3.2 3.0 3.2 3.6 4.2 5.0 5.8
5.4 4.5 3.6 2.8 2.2 2.0 2.2 2.8 3.6 4.5 5.4
5.1 4.1 3.2 2.2 1.4 1.0 1.4 2.2 3.2 4.1 5.1
5.0 4.0 3.0 2.0 1.0 0.0 1.0 2.0 3.0 4.0 5.0
5.1 4.1 3.2 2.2 1.4 1.0 1.4 2.2 3.2 4.1 5.1
5.4 4.5 3.6 2.8 2.2 2.0 2.2 2.8 3.6 4.5 5.4
5.8 5.0 4.2 3.6 3.2 3.0 3.2 3.6 4.2 5.0 5.8
6.4 5.7 5.0 4.5 4.1 4.0 4.1 4.5 5.0 5.7 6.4
7.1 6.4 5.8 5.4 5.1 5.0 5.1 5.4 5.8 6.4 7.1 ];

Z2 = [
  0 1 2 3 4 5 6 7 8 9 10
 -1 0 1 2 3 4 5 6 7 8 9
 -2 -1 0 1 2 3 4 5 6 7 8
 -3 -2 -1 0 1 2 3 4 5 6 7
 -4 -3 -2 -1 0 1 2 3 4 5 6
 -5 -4 -3 -2 -1 0 1 2 3 4 5
 -6 -5 -4 -3 -2 -1 0 1 2 3 4
 -7 -6 -5 -4 -3 -2 -1 0 1 2 3
 -8 -7 -6 -5 -4 -3 -2 -1 0 1 2
 -9 -8 -7 -6 -5 -4 -3 -2 -1 0 1
-10 -9 -8 -7 -6 -5 -4 -3 -2 -1 0 ];

Now I have a table of Z1(X,Y) and a table of Z2(X,Y) and I wanna interpolate the values of x and y for given (z1, z2), e.g., providing (z1, z2) = (2.9, 1), (x, y) is expected to be (2.5, 1.5).

Any existing function or any solution?

Subject: multi-object interpolate

From: Matt J

Date: 15 Nov, 2012 18:39:20

Message: 2 of 4

"Ha" wrote in message <k83b48$j6$1@newscl01ah.mathworks.com>...
>
> Now I have a table of Z1(X,Y) and a table of Z2(X,Y) and I wanna interpolate the values of x and y for given (z1, z2), e.g., providing (z1, z2) = (2.9, 1), (x, y) is expected to be (2.5, 1.5).
>
> Any existing function or any solution?
===============

f=@(xi,yi,Z) interp2(x,y,Z,xi,yi);

out=[f(x,y,Z1), f(x,y,Z2)];

Subject: multi-object interpolate

From: Ha

Date: 15 Nov, 2012 19:11:14

Message: 3 of 4

"Matt J" wrote in message <k83cso$7bq$1@newscl01ah.mathworks.com>...
> "Ha" wrote in message <k83b48$j6$1@newscl01ah.mathworks.com>...
> >
> > Now I have a table of Z1(X,Y) and a table of Z2(X,Y) and I wanna interpolate the values of x and y for given (z1, z2), e.g., providing (z1, z2) = (2.9, 1), (x, y) is expected to be (2.5, 1.5).
> >
> > Any existing function or any solution?
> ===============
>
> f=@(xi,yi,Z) interp2(x,y,Z,xi,yi);
>
> out=[f(x,y,Z1), f(x,y,Z2)];

The Z1(X,Y) table and the Z2(X,Y) table are known.

The value of z1 and the value of z2 are known.

The value of x and the value of y corresponding to (z1, z2) are expected to be known.

There could be many groups of (x, y) meeting Z1(x,y) == z1 or Z2(x,y) == z2. But there should be an exclusive group of (x,y) meeting Z1(x,y) == z1 and Z2(x,y) == z2.

Subject: multi-object interpolate

From: Matt J

Date: 16 Nov, 2012 14:50:23

Message: 4 of 4

"Ha" wrote in message <k83eoi$eqq$1@newscl01ah.mathworks.com>...
> "Matt J" wrote in message <k83cso$7bq$1@newscl01ah.mathworks.com>...
> > "Ha" wrote in message <k83b48$j6$1@newscl01ah.mathworks.com>...
> > >
> > > Now I have a table of Z1(X,Y) and a table of Z2(X,Y) and I wanna interpolate the values of x and y for given (z1, z2), e.g., providing (z1, z2) = (2.9, 1), (x, y) is expected to be (2.5, 1.5).
> > >
> > > Any existing function or any solution?
> > ===============
> >
> > f=@(xi,yi,Z) interp2(x,y,Z,xi,yi);
> >
> > out=[f(x,y,Z1), f(x,y,Z2)];
>
> The Z1(X,Y) table and the Z2(X,Y) table are known.
>
> The value of z1 and the value of z2 are known.
>
> The value of x and the value of y corresponding to (z1, z2) are expected to be known.
>
> There could be many groups of (x, y) meeting Z1(x,y) == z1 or Z2(x,y) == z2. But there should be an exclusive group of (x,y) meeting Z1(x,y) == z1 and Z2(x,y) == z2.
========================



 [~,idx]=min( abs(z1-Z1(:)) + abs(z2-Z2(:)) );

 xy0=[X(idx), Y(idx)]; %Initial guess


 fun=@(xy) abs(z1 - interp2(X,Y,Z1, xy(:,1),xy(:,2))) + abs(z2 - interp2(X,Y,Z2, xy(:,1),xy(:,2)))

 xy=fminsearch(fun,xy0);

Tags for this Thread

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.

Contact us