1
votes

I try to save a map as a *.mat file which is quite big. (somewhere around 4 or 5gigs. I cannot be sure because I could never save the file...)

the map is generated by:

[amap, ~] = load_audio(config);

and saved later on by

save('audioMap', 'amap');

Now the generated file is only 218 bytes but no errors occur. Trying to read the contents of the file with whos('-file', 'audioMap.mat') results in the following error:

Warning: Unable to read some of the variables due to unknown MAT-file error.

every record of the map is a cell with 6 values. Now querying the size of the map in the Matlab workspace results in the following output:

Name         Size            Bytes  Class             Attributes
amap      2279x1               112  containers.Map

Now clearly the size is not correct but I am able to iterate through the map and all data is present. When querying the size of a record it is approximately 2.5MB.

I also tried to save the variable from the workspace with right-click and save-as with the same result. Anyone got any ideas why Matlab is not able to properly save this map?

1
Have you tried saving it using the -v7.3 flag. It's clear that MATLAB is thinking that the object is much smaller than it is so it wouldn't issue the normal warning about using this flag. - Suever
Also, what's actually inside each of those map elements? Are they custom objects? - Suever
It might be an issue with the serialisation which is required to save objects. Is the containers.Map your only object oriented data structure? If so try amap_struct=struct(amap) and save the resulting struct. There is no automatism to get back the objects, but you could verify if all data is present after loading (amap_struct.serialisation.values) - Daniel
@Suever so the layout of one record is: double vector, double vector, string, string, integer, string. So no custom object just plain Matlab data types - Lukas Häfliger
@LukasHäfliger This may be worth filing a bug report with The Mathworks. I believe that it's a fundamental limitation of objects (MATLAB can't determine their true size) but this is pretty bad. - Suever

1 Answers

1
votes

You where attempting to write a MAT-File version 7.0 which has a maximum variable size of 2^31 bytes=2GB

When you attempt to write Variables larger than the limit, the expected behaviour would be to receive a warning when saving the variable.

Warning: Variable 'varname' cannot be saved to a MAT-file whose version is older than 7.3. To save this variable, use the -v7.3 switch. Skipping...

For some reason the warning was not raised, but beeing unable to write such large objects is the expected behaviour.