MATLAB: Create an anonymous function after Symbolic differentiation

differentiationfunction handlesymbolicSymbolic Math Toolbox

I want to differentiate a function f and the calculate the derivative of f at value of x. How can I do that? for example:
syms x
f=@(x) x^3+3*x+1;
g=diff(f(x))
Preferably I would like to create a function handle of the derivative and then calculate the derivative at x.

Best Answer

Almost there!
gfun = matlabFunction(g)
g(2)