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

Learn moreOpportunities for recent engineering grads.

Apply Today**New to MATLAB?**

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.*

Answer by Walter Roberson
on 15 Mar 2013

Accepted answer

Perhaps you want to use matlabFunction() ?

Show 2 older comments

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.

## 0 Comments