Using Cell Arrays in Interpolants

8 ビュー (過去 30 日間)
swenia
swenia 2017 年 12 月 5 日
コメント済み: swenia 2017 年 12 月 7 日
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?

採用された回答

Nicolas Schmit
Nicolas Schmit 2017 年 12 月 6 日
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 件のコメント
Nicolas Schmit
Nicolas Schmit 2017 年 12 月 7 日
swenia
swenia 2017 年 12 月 7 日
Thank you!

サインインしてコメントする。

その他の回答 (0 件)

カテゴリ

Help Center および File ExchangeCreating and Concatenating Matrices についてさらに検索

製品

Community Treasure Hunt

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

Start Hunting!

Translated by