mahalex / MatFileHandler

MATLAB .mat-file reading/writing API for .NET Standard
MIT License
40 stars 12 forks source link

Matlab 7.3 support #1

Open simmarn opened 6 years ago

simmarn commented 6 years ago

Hi!

MatFileHandler works brilliantly with Matlab 5.0 mat files. But I need support for reading Matlab 7.0. Is that in the pipe?

Right now I get when trying to read:

Unhandled Exception: System.NotSupportedException: Unknown element.
   at MatFileHandler.DataElementReader.Read(BinaryReader reader)
   at MatFileHandler.MatFileReader.Read(BinaryReader reader)
   at MatFileHandler.MatFileReader.Read()
   at MatReaderTest.Program.Main(String[] args) in C:\Users\Martin Olausson\source\repos\MatReader\MatReader\Program.cs:line 28
mahalex commented 6 years ago

Thanks for your feedback! I think Matlab 7.0 files are supported, as long as they only contain "ordinary" things like matrices, structure arrays, cell arrays, etc. However, reading Matlab "objects" (instances of user-defined Matlab classes) is not currently supported. The documentation for object storage seems scarce (I believe the official documentation is non-existent). Could you please share some file that you cannot import, and I'll take a closer look at it? This way we will be really sure what we're talking about.

simmarn commented 6 years ago

Certainly. Here you have the Matlab 7.0 file I can not open. I do not think it contains any "objects". https://simmarn.mydns.se/nextcloud/index.php/s/k3rA4Z4P4egiDqG

mahalex commented 6 years ago

It looks like this file is actually in Matlab 7.3 format. It was produced by libmatio rather than Matlab (and it incorrectly states that it's Matlab 7.0 in the comment). Supporting 7.3 format would mean dealing with the horrible HDF5 format. A year ago (when I last researched HDF5) it seemed close to impossible. To my knowledge, there are still no native C# libraries for accessing HDF5 data, so I would have to rely on external C libraries, which doesn't sound exciting to me. Maybe the situation has changed since then, so I'll try to look into it again. In any case, I don't think there is a quick fix for that, sorry!

simmarn commented 6 years ago

OK. Thanks for checking.