Borrar filtros
Borrar filtros

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

18 visualizaciones (últimos 30 días)
ercan duzgun
ercan duzgun el 15 de Feb. de 2017
Comentada: ercan duzgun el 15 de Ag. de 2019
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.

Respuesta aceptada

Stephen23
Stephen23 el 15 de Feb. de 2017
Editada: Stephen23 el 15 de Feb. de 2017
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

Más respuestas (2)

John D'Errico
John D'Errico el 15 de Feb. de 2017
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 el 14 de Ag. de 2019
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)

Categorías

Más información sobre Loops and Conditional Statements en Help Center y File Exchange.

Etiquetas

Productos

Community Treasure Hunt

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

Start Hunting!

Translated by