3D look up interp3

조회 수: 9 (최근 30일)
Sivateja Maturu
Sivateja Maturu 2019년 4월 9일
편집: Gabriel Felix 2021년 4월 28일
May I know, I have a problem with 3D lookup table. I have 16x40x3 table, all populated. But the values ​​I want to have 16x79x9 values ​​which all exists in the limits. And I am using interp3 (x, y, z, V, x ', y', z '). And the sizes are
x: 16 valued array
y: 40 valued array
z: 3 valued array
V: 16x40x3 matrix
x ', y', z 'are scalars
May I know what is wrong here? I find the error.
Error using gridded Interpolant
The grid vectors do not define a grid of points that matches the given values.
Please help

답변 (2개)

David Wilson
David Wilson 2019년 4월 9일
You don't give us much to work on, so I'll make up some data that follow your dimensions.
x = linspace(-1,1,16); y =linspace(-1,1,40); z = linspace(-1,1,3);
[X,Y,Z] = meshgrid(x,y,z);
V = sin(X)+cos(Y)+Z.^2; % some function
This generates a data cube in the dimensions you said (16*40*3). I've made up a well behaved function (since I had nothing to go on.)
Now we will generate an interpolating grid cube of the dimensions you wanted (16*79*9) using meshgrid.
xi = linspace(-0.5,1,16); yi = linspace(-0.8,0.8,79); zi = linspace(-1,1,9);
[Xi,Yi,Zi] = meshgrid(xi,yi,zi);
Now we are ready to interpolate in 3D.
Vi = interp3(X,Y,Z,V, ...
Xi, Yi, Zi)
The variable Vi is your interpolated output.
>> size(Vi)
ans =
79 16 9
  댓글 수: 1
Sivateja Maturu
Sivateja Maturu 2019년 4월 9일
In my case I am looking for a interpolation of scalars. I mean,xi, yi,zi are scalrs in my case which are within limits of x,y,z

댓글을 달려면 로그인하십시오.


David Wilson
David Wilson 2019년 4월 9일
In that case it's easy, just use them as the interpolated input: say zt x=0.5, y=0.7,z=-0.3
Vi = interp3(X,Y,Z,V, ...
0.5, 0.7, -0.3)
  댓글 수: 1
Gabriel Felix
Gabriel Felix 2021년 4월 28일
편집: Gabriel Felix 2021년 4월 28일
interp3(X,Y,Z,V,Xq,Yq,Zq):
- X is the variable that contains the base values of the columns of V.
- Y is the variable that contains the base values of the rows of V.
- Z is the variable that contains the base values of the 3rd dimension of V
The names of variables X, Y and Z further confuses us, because they dont mean the literal vectors X, Y and Z. They express the reference values for:
X: Columns - disposed on the rows
Y: Rows - disposed on the columns
Z: 3rd dimension - disposed on the 3rd dimension
Ex.
V = [1 2 3 4 5 ;
6 7 8 9 10]
sizeX = 5 -> 5 columns
sizeY = 2 -> 2 rows
sizeZ = 1 -> 1 3rd dim
interp3(V,5,2,1) = 10
Ex.
V(:,:,1) = [
1 2 3 4
5 6 7 8
9 10 11 12]
V(:,:,1) = [
13 14 15 16
17 18 19 20
21 22 23 24]
sizeX = 4 -> 4 columns
sizeY = 3 -> 3 rows
sizeZ = 2 -> 2 3rd dim
interp3(V,3,3,2) = 19
Obs.: I didnt use the X,Y,Z values because I would have to create them and it would take long
The same applies to interp2

댓글을 달려면 로그인하십시오.

카테고리

Help CenterFile Exchange에서 Resizing and Reshaping Matrices에 대해 자세히 알아보기

Community Treasure Hunt

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

Start Hunting!

Translated by