I would like to know if there is a way to vectorize the calls of different function handles, which are stored in a cell array and have of course input values themselves. I basically have a model, which looks like:
MyModel=cell(2,1);
MyModel{1}=@(a,b) a+b;
MyModel{2}=@(a,b) a-b;
a=[1,2];
b=[2,1];
ModelNumber=[1,2];
Now I would like to call MyModel{ModelNumber(1)}
at a(1)
and b(1)
and MyModel{ModelNumber(2)}
at a(2)
and b(2)
. Of course it can be done with a for
loop. However, the real thing will take a lot of time, if I use a loop. So is there a way to vectorize the problem in a way that something like
MyModel{ModelNumber(:)}(a(:),b(:))
works? I already looked at cellfun, but couldn't find an answer.
Thanks in advance! Ingo