expr = a*x^2
expr = ![](https://www.mathworks.com/matlabcentral/answers/uploaded_files/1763969/image.png)
f = matlabFunction(expr, 'vars', x)
end
Warning: Free variable 'a' must be included in 'Vars' value.
So you have the problem that a is needed but it is not input to the function.
On the other hand,
expr = a*x^2
expr =
![](https://www.mathworks.com/matlabcentral/answers/uploaded_files/1763974/image.png)
f = matlabFunction(expr, 'vars', x)
f =
@(x)x.^2.*(4.9e+1./5.0)
This has the disadvantage that the value of a is expanded in-line
There is no way with the Symbolic Toolbox to generate a function referring to a captured variable by name