"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(z1Z1(:)) + abs(z2Z2(:)) );
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);
