MATLAB: String function derivative

diff sym matlabfunction

I'm trying to do
F_diff_x = matlabFunction(diff(sym(f), 'x'));
when f is
f = get(handles.equation,'String');
And sometimes I can calculate the derivative, sometimes not Becouse I get:
??? Error using ==> sym.sym>convertExpression at 2515
Error: 'expression' expected [line 1, col 12]
Error in ==> sym.sym>convertChar at 2426
s = convertExpression(x);
Error in ==> sym.sym>convertCharWithOption at 2410
s = convertChar(x);
Error in ==> sym.sym>tomupad at 2164
S = convertCharWithOption(x,a);
Error in ==> sym.sym>sym.sym at 111
S.s = tomupad(x,'');
Error in ==> moo>bc_Callback at 383
F_diff_x = matlabFunction(diff(sym(f), 'x'));
How can I do this in a different way?

Best Answer

The dot operators are not valid MuPAD code, and it is MuPAD code that must be sym()'d, not MATLAB code.
Not 'sin(x)+x.^2+cos(2*y)' but 'sin(x)+x^2+cos(2*y)'
Related Question