フィルターのクリア

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

13 ビュー (過去 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
  1 件のコメント
ercan duzgun
ercan duzgun 2017 年 2 月 15 日
Thank you. Yes, this works.

サインインしてコメントする。

その他の回答 (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.)
  1 件のコメント
ercan duzgun
ercan duzgun 2017 年 2 月 15 日
Thank you. Nice programming algorithm.

サインインしてコメントする。


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)
  1 件のコメント
ercan duzgun
ercan duzgun 2019 年 8 月 15 日
This code also works fine. Thank you Phillip Resor.

サインインしてコメントする。

カテゴリ

Help Center および File ExchangeLoops and Conditional Statements についてさらに検索

タグ

Community Treasure Hunt

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

Start Hunting!

Translated by