1D griddedInterpolant with 2D query points, does not work?

1 view (last 30 days)
I'm trying to use griddedInterpolant with nD grid sizes, and ND query point matrices, where nD does not equal ND. This works well, except when I define a 1D griddedInterpolant, and have 2D or higher dimensional query point matrices.
See below for an example. The provided code works without error in 2014b, the commented lines give an error when uncommented.
Is there an alternative way of programming this, where I can treat the 1D case the same as the general case?
x = 1:8;
V1 = rand(1,8);
V2 = rand(8,8);
V3 = rand(8,8,8);
I1 = griddedInterpolant({x},V1);
I2 = griddedInterpolant({x,x},V2);
I3 = griddedInterpolant({x,x,x},V3);
X1 = ones(1,3);
X2 = ones(3,3);
X3 = ones(3,3,3);
I1(X1)
I2(X1,X1)
I3(X1,X1,X1)
% I1(X2)
I2(X2,X2)
I3(X2,X2,X2)
% I1(X3)
I2(X3,X3)
I3(X3,X3,X3)

Answers (1)

Richa Gupta
Richa Gupta on 21 Jul 2015
Hi Chris,
For creating a 1-D interpolant object, you can pass x, a set of points, and v, a vector of the same length containing the corresponding values.
F = griddedInterpolant(x,v)
Now when you query the Interpolant, the griddedInterpolant, F, is evaluated in the same way as you would call a function. So, you cannot have 2D or higher dimensional query points but only a vector or a 1D matrix. The commented lines throwing an error is the expected behavior because you are first passing a 2D (X2) query point and then a 3D (X3) query point to the 1D griddedInterpolant “I1” that you created.
Hope this helps.
Richa
  1 Comment
Chris
Chris on 22 Jul 2015
I'm not sure I completely understand your answer, but most functions work fine with 2D or 3D inputs. See for example the code below, with X1, X2 and X3 defined in the same way as above. Similar behavior I'd also like to get from griddedInterpolant with 1D value grids, and multi-dimensional query points.
f = @(x) x.^2;
f(X1)
f(X2)
f(X3)

Sign in to comment.

Categories

Find more on Interpolation in Help Center and File Exchange

Community Treasure Hunt

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

Start Hunting!