mahalex / MatFileHandler

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

Unable to read mat file created with MATLAB 2020b #18

Open EtHRoVel opened 3 years ago

EtHRoVel commented 3 years ago

While reading of this simple mat file matlab.zip I get an IndexOutOfRangeException at MatFileReader.Read(). Stack trace is:

   at MatFileHandler.SubsystemDataReader.GatherClassAndObjectInformation(Dictionary`2 classIdToName, String[] fieldNames, Dictionary`2 objectClasses, Dictionary`2 objectPositionsToValues, Dictionary`2 embeddedObjectPositionsToValues)
   at MatFileHandler.SubsystemDataReader.Read(Byte[] bytes, SubsystemData subsystemData)
   at MatFileHandler.MatFileReader.ReadRawVariables(BinaryReader reader, Int64 subsystemDataOffset, SubsystemData subsystemData)
   at MatFileHandler.MatFileReader.Read(BinaryReader reader)
   at MatFileHandler.MatFileReader.Read()
   at MatFileNugetTest.Program.Main(String[] args)

I have used the latest MatFileHandler Nuget package ver. 1.3.0.

Any idea why this happens?

mahalex commented 3 years ago

Thank you for the report! Looks like this file contains variables of some Simulink-specific types. MATLAB R2020b (without Simulink) actually refuses to read it. To be precise, it reads it, but spits a handful of warnings like "Warning: Variable 'BOOLEAN8' originally saved as a Simulink.AliasType cannot be instantiated as an object and will be read in as a uint32.", and the result is a variable BOOLEAN8 that is a 6x1 uint32 array with values [3707764736; 2; 1; 1; 1; 1]. I happen to have an idea what 3707764736 means, but I doubt that's what you would like to see. So I wouldn't call it a "MATLAB" .mat file, I would call it "Simulink" .mat file. That said, the exception that you get is probably not a proper way of reporting error (and it's not very informative). So I'll think about how to improve handling of types that are not built-in MATLAB types, but I don't think we are going to have support for Simulink types in the near future.