Using Cell Arrays in Interpolants

6 views (last 30 days)
swenia
swenia on 5 Dec 2017
Commented: swenia on 7 Dec 2017
I have a griddedInterpolant F and some of the input variables are in a cell array form. As an example, this is how I created the interpolant F:
[x,y,z] = ndgrid(-5:1:5);
t = x+y+z;
mycell = {x,y};
F = griddedInterpolant(mycell{:},z,t);
In reality, the size of the cell array mycell changes each time I run the code, and that's why I figured I have to use a cell array as an input. Up to this point everything works beautifully and I get my interpolant F without any problems.
Now I'd like to call the interpolant F in another function. When I have a single row for each input, everything works fine as shown in the following example:
testcell = {1,3};
F(testcell{:},5)
ans =
9
However, when I'd like to have each input in a vector form, the interpolant doesn't work and I get the following error:
testcell = {1,3; 2, 4};
F(testcell{:,:},[5;1])
Error using griddedInterpolant/subsref
Invalid arguments specified in evaluating the interpolant.
Because I don't know the dimensions (particularly number of columns) of my actual cell array, I can not break testcell apart manually. This means that my input data might be 3D, but I can't call the interpolant F as F(input1, input2, input3) because I don't know whether it is 3D. As a side note, the code does know the dimensions of the data. I'd like to use vector inputs for each input variable of F in order to call F for n number of cases at once without a for loop. (i.e. each input has a size of nx1, hence the output should also be a vector of nx1)
What is the right way to call the interpolant F in this case?

Accepted Answer

Nicolas Schmit
Nicolas Schmit on 6 Dec 2017
There is a problem with your last snippet of code. Here is how you should correct it.
testcell = {[1;3]; [2; 4]};
F(testcell{:},[5;1])
  4 Comments

Sign in to comment.

More Answers (0)

Categories

Find more on Interpolation in Help Center and File Exchange

Products

Community Treasure Hunt

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

Start Hunting!