How to back interpolation to find x from z and y?

18 次查看(过去 30 天)
I would like to do "back" interpolation to find an x value from the given values of z and y. (2Dimensional x,y,z matrix table is available). Is there any prepared MATLAB function for it?/ And how to do it in Simulink(Lookup Table Dynamic block is for 1D. I need 2D)?
As an example: x =[01 2 3 4 5]; y=[ 30 40 50 60]
z=[
1 2 3 4 5
3 4 5 6 7
5 6 7 8 10
7 8 10 10 13]
Table=
1 2 3 4 5
---------------
30 ! 1 2 3 4 5
40 ! 3 4 5 6 7
50 ! 5 6 7 8 10
60 ! 7 8 10 10 13
According to this given values, I would like to find the x value for a given data of y=43, and z=6.8
Thanks in advance.

采纳的回答

Stephen23
Stephen23 2017-2-15
编辑:Stephen23 2017-2-15
This is easy with interp2 and fzero:
>> X = [1,2,3,4,5]
>> Y = [30,40,50,60]
>> Z = [1,2,3,4,5;3,4,5,6,7;5,6,7,8,10;7,8,10,10,13]
>> y = 43;
>> z = 6.8;
>> fun = @(x)interp2(X,Y,Z,x,y)-z;
>> x = fzero(fun,mean(X))
x = 4.1538
And checking:
>> interp2(X,Y,Z,x,y)
ans = 6.8000

更多回答(2 个)

John D'Errico
John D'Errico 2017-2-15
Is there something already written in MATLAB to do this? No. Given that your problem is not terribly common, it would be unexpected if it was already written.
Is it possible to do? Yes. Not even that terribly difficult.
You have an array that essentially defines the relation z(x,y).
1. Use interp2 to interpolate the array along the line y = 43, so for each value of x, determine z at the given y value. The result will be a vector of z values, one for each location in x.
2. Find any pairs of locations that cross the desired z level.
3. Interpolate linearly to find x that yields the given z level exactly. (Well, exactly to within the accuracy of linear interpolation.)

Phillip Resor
Phillip Resor 2019-8-14
Just sorted this out using griddedInterpolant and thought others might find it useful
x = [1,2,3,4,5];
y = [30,40,50,60];
[X, Y] = ndgrid(x,y);
Z = [1,2,3,4,5;3,4,5,6,7;5,6,7,8,10;7,8,10,10,13]'; % transpose to match ndgrid
yp = 43;
zp = 6.8;
F = griddedInterpolant(X, Y, Z);
fun = @(xp)F(xp,yp)-zp;
xp = fzero(fun,mean(x))
And checking:
F(xp,yp)

类别

Help CenterFile Exchange 中查找有关 Loops and Conditional Statements 的更多信息

标签

Community Treasure Hunt

Find the treasures in MATLAB Central and discover how the community can help you!

Start Hunting!

Translated by