필터 지우기
필터 지우기

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

조회 수: 18 (최근 30일)
ercan duzgun
ercan duzgun 2017년 2월 15일
댓글: ercan duzgun 2019년 8월 15일
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