I am trying to read a matlab file using scipy
import scipy.io as sio
data = sio.loadmat(filepath)
but I get the error
ValueError: Did not fully consume compressed contents of an miCOMPRESSED element. This can indicate that the .mat file is corrupted.
In Matlab I can open this file without any problem. I also tried to save it again, but nothing changed... Can you help me?
Here: https://drive.google.com/drive/folders/0B3vXKJ_zYaCJanZfOUVIcGJyR0E you can find 2 files saved in the same way..
I can open part_000, but not part_001.... why? :(
The problem seems to be caused by the compression. .mat
files are compressed automatically from version 7 onward.
Therefore, I suggest trying to save the file in the earlier, uncompressed .mat
file version 6:
save(filename, 'data', '-v6');
The problem is with scipy.io.loadmat
's verify_compressed_data_integrity
keyword argument, which defaults to True
. It's trying to do some error checking of the headers, but can raise an error even when the data is extracted just fine. See this related GitHub issue. I'm unsure of the implications of switching this off full-time, but if you use the following, it should resolve your issue in the meantime (I can't check it against your data, it's no longer available at the provided URL).
import scipy.io as sio
data = sio.loadmat(filepath, verify_compressed_data_integrity=False)
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