I'm trying to manipulate with Mathematica symbolic expression created in Matlab. I'm using the MATLink package, and I've succedeed in importing numerical variables, but not symbolic ones :

MEvaluate["syms g real"]
MEvaluate["syms l real"]
MEvaluate["u = g + l"]

will output :

u = 
g + l % Matlab correctly defines the variable
{}    % Mathematica doesn t succeed in getting the variable

Anyone with experience in dealing with this ?

  • 3
    $\begingroup$ MATLAB/Mupad's symbolic variables are not supported in MATLink. If you want to use symbolic variables, then why not do it in Mathematica itself? It's much more powerful... $\endgroup$
    – rm -rf
    Oct 24 '13 at 16:12
  • $\begingroup$ As rm said, symbolic variables are not supported in MATLink. But MGet["u"] should return $Failed here and not {}. What operating system are you using? $\endgroup$
    – Szabolcs
    Oct 24 '13 at 19:27
  • $\begingroup$ I'm using Windows 7. Is there another package that could do the trick, or is doing all the work with Mathematica the only way ? Thanks a lot for your help ! $\endgroup$
    – user10179
    Oct 24 '13 at 21:24
  • $\begingroup$ I am not aware of any package that can do this. $\endgroup$
    – Szabolcs
    Oct 25 '13 at 2:50
  • 1
    $\begingroup$ @user10179 Matlab is just the wrong tool for symbolic stuff (I am very tempted to widely generalize here), so the sooner you realize that the more productive you will be. $\endgroup$ Oct 25 '13 at 11:33

MATLink does not support transferring symbolic variables. If you need to do symbolic calculations I would recommend using Mathematica for them. Is there a symbolic computation you cannot easily do in Mathematica that you can do with MATLAB?

If you still want to transfer symbolic expressions between the systems, you can convert them to a string, then try to parse the string in Mathematica. This will require some additional effort except in the simplest of cases when the syntaxes between the two systems are close enough.

In[1]:= << MATLink`

In[2]:= OpenMATLAB[]

In[3]:= MEvaluate["
 syms g l real

Out[3]= ">>  
u =

g + l


In[4]:= MEvaluate["char(u)"]

Out[4]= ">> 
ans =

g + l


In[5]:= MGet["ans"]

Out[5]= "g + l"

In[6]:= ToExpression[%]

Out[6]= g + l

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.