How can I interpolate a data set given by 5 "inputs"?

11 次查看(过去 30 天)
I have a question related to an interpolation process. My data set is given in the following way:
An array Y which contains several vectors as follows:
Y = [Y1; Y2; Y3; Y4; Y5; Y6; .... Y32];
Each of these vector is defined as: Y1 = [0,0,0,0,0], Y2 = [0,0,0,0,1],....
Then, every Y_i vector has an evaluated parameter. For instance, V(Y1) = 80, V(Y2) = 90 leading to a vector V whose length is 32.
My goal is to get the value for any configuration of the Y vector, for example, xq = [0,0,0.5,0,1].
I tried it via the interpn function as follows:
vq = interpn(Y,V,xq,'linear');
Where,
[x1,x2,x3,x4,x5] = ndgrid(0:0.5:1);
xq = [x1(:) x2(:) x3(:) x4(:) x5(:)];
But I obtained an error using griddedInterpolant/subsref -> "The input data has inconsistent size".
Is it possible to carry out this kind of interpolation? Thanks in advance.
  2 个评论
dpb
dpb 2019-11-26
"goal is to get the value for any configuration of the Y vector, ..."
What does "configuration" mean here, exactly? A lookup of a five-vector?
Could help by attaching the array and giving some sample inputs with expected outputs (and why are the correct ones)...
Antonio Jimenez-Carrascosa
"Configuration" means I would need the interpolated V value for every components' combination of vector Y which is described by 5 parameters from 0 to 1 as e.g. [1,1,1,1,1]. Let me describe in-depth how the arrays look like:
Y1 = [ 0, 0, 0, 0, 0 ];
Y2 = [ 0, 0, 0, 0, 1 ];
Y3 = [ 0, 0, 0, 1, 0 ];
Y4 = [ 0, 0, 0, 1, 1 ];
Y5 = [ 0, 0, 1, 0, 0 ];
Y6 = [ 0, 0, 1, 0, 1 ];
Y7 = [ 0, 0, 1, 1, 0 ];
Y8 = [ 0, 0, 1, 1, 1 ];
Y9 = [ 0, 1, 0, 0, 0 ];
Y10 = [ 0, 1, 0, 0, 1 ];
Y11 = [ 0, 1, 0, 1, 0 ];
Y12 = [ 0, 1, 0, 1, 1 ];
Y13 = [ 0, 1, 1, 0, 0 ];
Y14 = [ 0, 1, 1, 0, 1 ];
Y15 = [ 0, 1, 1, 1, 0 ];
Y16 = [ 0, 1, 1, 1, 1 ];
Y17 = [ 1, 0, 0, 0, 0 ];
Y18 = [ 1, 0, 0, 0, 1 ];
Y19 = [ 1, 0, 0, 1, 0 ];
Y20 = [ 1, 0, 0, 1, 1 ];
Y21 = [ 1, 0, 1, 0, 0 ];
Y22 = [ 1, 0, 1, 0, 1 ];
Y23 = [ 1, 0, 1, 1, 0 ];
Y24 = [ 1, 0, 1, 1, 1 ];
Y25 = [ 1, 1, 0, 0, 0 ];
Y26 = [ 1, 1, 0, 0, 1 ];
Y27 = [ 1, 1, 0, 1, 0 ];
Y28 = [ 1, 1, 0, 1, 1 ];
Y29 = [ 1, 1, 1, 0, 0 ];
Y30 = [ 1, 1, 1, 0, 1 ];
Y31 = [ 1, 1, 1, 1, 0 ];
Y32 = [ 1, 1, 1, 1, 1 ];
Y = [Y1 Y2 Y3 Y4 Y5 Y6 Y7 Y8 Y9 Y10 Y11 Y12 Y13 Y14 Y15 Y16 Y17 Y18 Y19 Y20 Y21 Y22 Y23 Y24 Y25 Y26 Y27 Y28 Y29 Y30 Y31 Y32];
Then, each Y_i "configuration" has an associated V value:
V = [ 80, 90 ,31, 750, ...., -400, 0 ]; where length(V) is 32 as in the case of Y.
Therefore, the idea is to get the V value for other kind of Y vector described by its 5 components. For example, for xq = [0, 1, 1, 0.5, 0.2];
I hope it is clearer! Thanks for the answer!

请先登录,再进行评论。

采纳的回答

Guillaume
Guillaume 2019-11-26
TLDR: The Y and xq you've constructed work for scatteredInterpolant but not for griddedInterpolant which uses a different format.
interpn expects gridded data in a full grid format, which is not what your Y represents, at least in its current form. To represent gridded data, you would have to pass either 5 vectors (each [0 1] it sounds) or 5 5-D matrices
Assuming your Y truly represents all distincts point of a full grid (which it should be if you have 32 values) you can transform your input data into the format required by interpn (or griddedInterpolant which I would recommend over interpn):
griddedvalues = accumarray(Y + 1, V); %only works if Y values are integers. + 1 to make the 0 valid indices
You can then create your interpolant with
interpolant = griddedInterpolant(repmat({[0 1]}, 1, 5), griddedvalues);
and query it as
result = interpolant(x1, x2, x3, x4, x5)
Unfortunately, with gridded interpolant (and interpn you can't pass the query point in the xq format you created.
---
The syntax you've used however works with scatteredInterpolant.
interpolant = scatteredInterpolant(Y, V);
result = interpolant(xq)
scatteredInterpolant is probably slower than griddedInterpolant for properly gridded data but it's certainly easier to use with your Y and xq.

更多回答(0 个)

类别

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