Discover MakerZone

MATLAB and Simulink resources for Arduino, LEGO, and Raspberry Pi

Learn more

Discover what MATLAB® can do for your career.

Opportunities for recent engineering grads.

Apply Today

How automatic insert (once defined) symbolic expression from script or workspace to function?

Asked by Vladimir on 14 Mar 2013

Hi. I have symbolic expressions in a script file (that represent calculated partial derivatives. Because I need, at each iteration, that get the numeric value of the symbolic expression depending on the new set values of variables, I created a function, that compute this) Since that symbolic expression is different from case to case, is there a possibility that the expression automatic import in function without manual typing these expressions. I want to define this expression in one place in the script file, and than when you call functions, this expression be automatically loaded in function. Thank you in advance.




No products are associated with this question.

1 Answer

Answer by Walter Roberson on 15 Mar 2013
Accepted answer

Perhaps you want to use matlabFunction() ?


Vladimir on 15 Mar 2013

Thank you dear Walter. The same can be achieved if we take

f = matlabFunction(fs);

If we then use command for automatic save and form function 'state'

g=matlabFunction(f, 'file','state');

fk=state(xk(1,k-1), xk(2,k-1), xk(3,k-1), xk(4,k-1), xk(5,k-1), xk(6,k-1), xk(7,k-1));

Thank you again, you sent me to the right way.

Walter Roberson on 15 Mar 2013

Be careful, matlatFunction idea of which order the variables should be in are not necessarily the same as yours. To avoid surprises I recommend using the 'vars' parameter if there are multiple variables.

Vladimir on 15 Mar 2013

I tried it and I got burned. You're right, it must be noted the order of the variables using the 'vars'. Greetings!

Walter Roberson

Contact us