MATLAB: How to pass vectors as arguments for functions created using str2func

vector str2func

f=str2func('@(x,y,z) x+y+z');
w=[1,1,1];
y=f(w) % want to compute f(1,1,1) using vector x
This gives an error when I tried to compute y
Thanks in Advance for your help !!

Best Answer

It has nothing to do with str2func. You need to define the function differently,
f=str2func('@(x) sum(x)');
or
f=str2func('@(x) x(1)+x(2)+x(3)');