This function gave me a lot of headache.
For functions like
f1 = @(x1,x2) x1*x2
You can do
output = arrayfun(f1,x1,x2);
where x1 and x2 are input columns.
However, if you're doing a generalized program, where f1
could have any number of inputs and you need a generalized input matrix like X, you'll need, for example
f1 = @(x1,x2,x3,x4,x5) 2*x1+4*x2+10*x3+0.2*x4+x5;
output = arrayfun(f1,num2cell(X,1){:});
where X
represents a matrix with 5 columns representing x1
through x5
For example:
X = [1, 2, 3, 4, 5;
6, 7, 8, 9, 0;];