Take the 2-minute tour ×
Mathematica Stack Exchange is a question and answer site for users of Mathematica. It's 100% free, no registration required.

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"]
MGet["u"]

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 ?

share|improve this question
3  
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... –  rm -rf Oct 24 '13 at 16:12
    
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? –  Szabolcs Oct 24 '13 at 19:27
    
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 ! –  user10179 Oct 24 '13 at 21:24
    
I am not aware of any package that can do this. –  Szabolcs Oct 25 '13 at 2:50
1  
@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. –  Leonid Shifrin Oct 25 '13 at 11:33
add comment

1 Answer 1

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
 u=g+l"]

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
share|improve this answer
add comment

Your Answer

 
discard

By posting your answer, you agree to the privacy policy and terms of service.

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