MATLAB: An array of griddedInterpolants

griddedinterpolantMATLAB

Hello!
I was wondering if you could suggest a way of resolving a little problem of mine (I guess it must be something very basic). In my project I need to keep track of multiple griddedInterpolant objects, each one connecting the same one-dimensional grid with one of many other one-dimensional grids (see the code snippet below). I need to store these griddedInterpolants somehow, and an array seems like a natural choice. However, I keep receiving errors to the effect that it is not possible (apparently Matlab tries to cast griddedInterpolants as doubles; I have tried a cell arry, but of no avail).
Would you happen to know if there is a solution? Is there some kind of List<griddedInterpolant> that I could use?
Thanks for the consideration!
xgr = linspace(0,1,100);
Ygr = repmat(xgr,5,1); % <-- Doesn't have to be five - could be any number really.
G = [];
for i=1:5
Ygr(i,1:100) = i .* Ygr(i,1:100);
G(i) = griddedInterpolant(xgr,Ygr(i,1:100)); % <-- This bit fires up the error.
end

Best Answer

xgr = linspace(0,1,100);
Ygr = repmat(xgr,5,1);
G = cell(5,1);
for i=1:5
Ygr(i,1:100) = i .* Ygr(i,1:100);
G{i} = griddedInterpolant(xgr,Ygr(i,1:100));
end