Trying to use interpn - converting sample data into ndgrid format

조회 수: 19 (최근 30일)
jh2011
jh2011 2018년 1월 5일
댓글: Star Strider 2018년 1월 5일
I'm trying to use the function interpn but it requires that I have everything in the ndgrid format. For example, I'm trying to execute this function:
Vq = interpn(X1,X2,X3,V,Xq1,Xq2,Xq3);
I'm trying interpolate the value of V given three variables (i.e. performing a 3D interpolation). I have X1, X2, and X3 set up:
X1 = 1:100; X2 = 1:50; X3 = 1:10;
That is, there are 100 points in X1, 50 points in X2, and 10 points in X1. However, my V is composed differently - it is a (100*50*10) by 1 vector, with each value in V corresponding to each value of X1, X2, and x3. In a sense, V looks like
[v(x1_1, x2_1, x3_1), v(x1_2, x2_1, x3_1), ... v(x1_100, x2_1, x3_1), v(x1_1, x2_2, x3_1), v(x1_2, x2_2, x3_1), ...].
How can I convert V into the ndgrid format?
I know that I can use griddatan but it is awfully slower than interpn.

답변 (2개)

Star Strider
Star Strider 2018년 1월 5일
Use the ndgrid (link) function.
  댓글 수: 2
jh2011
jh2011 2018년 1월 5일
How? ndgrid creates a grid if you put in the ranges of each dimension, but I have all the values flattened out in a vector
Star Strider
Star Strider 2018년 1월 5일
You can use ‘X1’, ‘X2’, and ‘X3’ as inputs to ndgrid.
‘V is composed differently - it is a (100*50*10) by 1 vector’
‘V’ is a matrix by that definition. Vectors are by definition (Nx1). If it is in fact a vector, use reshape to create it as a matrix.

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


Walter Roberson
Walter Roberson 2018년 1월 5일
reshape(V, 100, 50, 10)
  댓글 수: 2
jh2011
jh2011 2018년 1월 5일
What if V is computed based on [X1, X2, X3] created NOT in the ndgrid format?
Walter Roberson
Walter Roberson 2018년 1월 5일
If V is based on a rectangular grid, then reshape() it into grid form according to how it is laid out, and then if needed permute() it into ndgrid order.

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

카테고리

Help CenterFile Exchange에서 Interpolation에 대해 자세히 알아보기

Community Treasure Hunt

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

Start Hunting!

Translated by