HebiRobotics/MFL

Mat files saved by MFL cannot be read by Octave

Closed this issue · 8 comments

I have problem reading files saved with MFL when using Octave. I saved a simple mat file, as instructed in the readme:

MatFile matFile = Mat5.newMatFile()
	.addArray("var1", Mat5.newScalar(7));
Mat5.writeToFile(matFile, "data.mat");

and when I try to read it in Octave using load('data.mat'), I get an error:

error: load: failed to read matrix from file 'data.mat'

The file loads fine in Matlab.

I didn't have such problem when I was using MatFileRW library.

That's odd. I've never used Octave, but I wouldn't expect any problems with simple files like this.

I'll get Octave and see if I can reproduce the issue.

Ok, thanks. For the record I used Octave version 3.6.4

Actually, I'm having issues downloading it. Could you provide an equivalent .mat file generated with your version of Octave?

Yes, sure. Here is equivalent file saved in my Octave: data-octave.mat I saved it like that:

var1 = 7; 
save('data-octave.mat', '-mat', 'var1')

Here is also equivalent file written with MatFileRW library: data-matFileRW.mat

I believe I've found a possible issue. A missing subsysOffset is erroneously written as -1 while MATLAB and MatFileRW default to 0. I assume that this is tripping up the Octave reader, although it is weird that Octave itself initializes this to a garbage value 2314885530818453536. Maybe it requires a positive value?

PR #50 has a potential fix for this. Please check if Octave can load data-mfl-subsys-fix.mat.

The full header information is below:

mfl-le: Mat5File{description='MATLAB 5.0 MAT-file, Platform: Windows 10, Created on: Wed Aug 28 11:13:24 CEST 2019', subsysOffset=-1, byteOrder=LITTLE_ENDIAN, version=1}
mfl-be: Mat5File{description='MATLAB 5.0 MAT-file, Platform: Windows 10, Created on: Wed Aug 28 11:20:12 CEST 2019', subsysOffset=-1, byteOrder=BIG_ENDIAN, version=1}
matFileRW: Mat5File{description='MATLAB 5.0 MAT-file, Platform: Windows 10, CREATED on: Wed Aug 28 11:33:15 CEST 2019', subsysOffset=0, byteOrder=BIG_ENDIAN, version=1}
matlab: Mat5File{description='MATLAB 5.0 MAT-file, Platform: PCWIN64, Created on: Wed Aug 28 11:22:35 2019', subsysOffset=0, byteOrder=LITTLE_ENDIAN, version=1}
octave: Mat5File{description='MATLAB 5.0 MAT-file, written by Octave 3.6.4, 2019-08-28 09:30:46 UTC', subsysOffset=2314885530818453536, byteOrder=LITTLE_ENDIAN, version=1}

I checked that file and it loads correctly on my Octave

Ok. Thanks for your help. I'll get a new bugfix release out shortly.

Version 0.5.4 has been released to maven central