Is it possible to load matlab tables in python using scipy.io.loadmat?
What I'm doing:
In Matlab:
tab = table((1:500)')
save('tab.mat', 'tab')
In Python:
import scipy.io
mat = scipy.io.loadmat('m:/tab.mat')
But I cannot access the table tab in Python using mat['tab']
If you collect data with Matlab but want to work on it using Python (e.g. making nice graphs with matplotlib) you can export a . mat file and then import that into Python using SciPy. Remember that in Python indexing starts at 0, rather than 1 (which is how Matlab does it).
By default, Python is not capable of reading . mat files.
It is not possible to open it with a text editor (except you have a special plugin as Dennis Jaheruddin says). Otherwise you will have to convert it into a text file (csv for example) with a script. This could be done by python for example: Read . mat files in Python.
SciPy has many modules, classes, and functions available to read data from and write data to a variety of file formats.
The answer to your question is no. Many matlab objects can be loaded in python. Tables, among others, can not be loaded. See Handle Data Returned from MATLAB to Python
The loadmat
function doesn't load MATLAB tables. Instead a small workaround can be done. The tables can be saves as .csv
files which can then be read using pandas
.
In MATLAB
writetable(table_name, file_name)
In Python
df = pd.read_csv(file_name)
At the end, the DataFrame df
will have the contents of table_name
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With