I have a matrix with symbolic variable in MATLAB like this:
syms x
f = [x^2 x^3 x^4];
save ('sym.mat','f')
Thus I saved the f matrix as sym.mat. Now I want to import this matrix into python. So I tried this:
import scipy.io as sio
matrix = sio.loadmat('sym.mat')
sym = matrix['f']
But it didn't work. I got this error, which is just a regular python keyerror.
Traceback (most recent call last):
File "<stdin>", line 1, in <module>
KeyError: 'f'
However if f is not a symbolic matrix then this code works fine. Any ideas how I can deal with these matrices with symbolic variables?
keysofmatrix? Give us an idea of whatloadmatreturned. My guess is that MATLAB has saved a class and/or function that can't be translated intonumpystructures. I seen problems in previous SO questions with MATLAB functions and dates.sympy.numpyandscipydon't have any symbolic functionality, soloadmatcouldn't return the MATLAB equivalent even if it 'understood'syms. The best you can do is some how recreate them insympy.