unable to load mat file which was saved in python as savemat (at version 7.3) in 2021a matlab.
14 views (last 30 days)
Show older comments
I have a mat file which was created in python using savemat at version 7.3. The data is perfectly loading in matlab version 2017a but when i tried in version 2021a it is throwing this error "Not a binary MAT-file. Try load -ASCII to read as text". There is no problem with the data, I checked it with matlab version 2017a. Everytime the same file is loading in 2017 but not in 2021.
4 Comments
dpb
on 3 Jul 2022
" but when i recreated my original file in matlab 2017 with version 7.3, I could not read that file in matlab 2021."
Are you saying an all-MATLAB file from R2017b couldn't be read by R2021b?
If that is so w/o any Python utilities in the mix, that seems an issue; again if Python is involved I don't think you can blame that on TMW/MATLAB.
The content of the file may not be shared, but if it is related to a structure in a .mat file, you could certainly create the same structure with random data that could be shared.
But, we need more definitive description include actual code that can create the problem; simply descriptions and "doesn't work" isn't sufficient with which to do any debugging.
Al Danial
on 10 Jul 2022
If it's any consolation, I have no difficulty reading Python-created .mat files in 2022a. Here's Python code I used to test:
!/usr/bin/env python
from scipy.io import savemat
import numpy as np
a1 = np.array([5441, 32207], dtype=np.uint16)
a2 = np.array([[0.2785, 0.9575, 0.1576],
[0.5469, 0.9649, 0.9706]])
b = [ 'this is a', "list", 5+6j ]
c = { 'x' : -17.6, 'y' : 4.98 }
M = {}
M['a1'] = a1
M['a2'] = a2
M['b'] = b
M['c'] = c
savemat('by_python.mat', M)
which loads fine into MATLAB:
>> load by_python
>> whos
Name Size Bytes Class Attributes
Im 1x1 32 function_handle
a1 1x2 4 uint16
a2 2x3 48 double
ans 1x1 8 matlab.pyclient.PythonEnvironment
b 3x64 384 char
c 1x1 352 struct
>> a1
a1 =
1x2 uint16 row vector
5441 32207
>> a2
a2 =
0.2785 0.9575 0.1576
0.5469 0.9649 0.9706
>> b
b =
3x64 char array
'this is a '
'list '
'(5+6j) '
>> c
c =
struct with fields:
x: -17.6000
y: 4.9800
This is with Python version 3.8.8.
Answers (0)
See Also
Categories
Find more on Call Python from MATLAB in Help Center and File Exchange
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!