1

I have identical code in Matlab, identical data that was analyzed using two different computers. Both are Win 7 64 bit. Both Matlabs are 2014-a version. After the code finishes its run, I save the variables using save command and it outputs .mat file.

Is it possible to have two very different memory sizes for these files? Like one being 170 MB, and the other being 2.4 GB? This is absurd because when I check the variables in matlab they add up to maybe 1.5 GB at most. What can be the reason for this?

Does saving to .mat file compress the variables (still with the regular .mat extension)? I think it does because when I check the individual variables they add up to around 1.5 GB.

So why would one output smaller file size, but the other just so huge?

Daniel
  • 36,610
  • 3
  • 36
  • 69
ilyas
  • 609
  • 9
  • 25
  • Are you using `save` without any parameter (saves whole current workspace) or passing it only variables you want to save ... maybe local workspace on some pc was containing a lot of unsued variables. – CitizenInsane Feb 12 '15 at 14:30
  • yeah i am saving all. I need all the variables. – ilyas Feb 12 '15 at 14:32
  • My question was to know if current variables in current workspace are the same on the two pc at the time save command occurs (there may have been some extra ones, especially if code is a script and not a function). – CitizenInsane Feb 12 '15 at 14:36
  • Oh OK. No they are identical. – ilyas Feb 12 '15 at 14:39

2 Answers2

3

Mat in recent versions is HDF5, which includes gzip compression. Probably on one pc the default mat format is changed to an old version which does not support compression. Try saving specifying the version, then both PCs should result in the same size.

Daniel
  • 36,610
  • 3
  • 36
  • 69
  • I see so I should explicitly specify v8.3 (the version for 2014a) Is this because I had 2011 Matlab installed before? Looking into hdf5, is there a way to save workspace variables in this format? Or is this a method that matlab uses to "save" workspace variables? Also if we import data can we save it in hdf5 format so that it will be faster to import for future use? Or again is that achieved through .mat file? – ilyas Feb 12 '15 at 14:45
  • When I use "save file.mat -v8.3" it does not work. It gives the following error: Error using save Unknown command option. – ilyas Feb 12 '15 at 14:48
  • 8.3 is not a valid version, check your documentation for `save`. Mat in recent versions, i think starting with 7.0, is hdf5. – Daniel Feb 12 '15 at 14:56
  • I see. It is already using the latest format v7.3 for saving in the settings -> General. I also ran a command with -v7.3 and the mat file size was same: 2.4 GB. – ilyas Feb 12 '15 at 15:16
  • Another example: I tried a much smaller data, and on one computer it occupies 4 MB, on the other 9 MB. – ilyas Feb 12 '15 at 15:23
  • You got different sizes with the same data and `-v7.3`? – Daniel Feb 15 '16 at 23:40
0

I found the reason for this based on the following stackoverflow thread: MATLAB: Differences between .mat versions

Apparently one of the computers was using -v7 format which produces much smaller files. - v7.3 just inflates the files significantly. But this is ironical in my opinion since -v7.3 enables saving files larger than 2 GB, which means they will be much much larger when saved in .mat file.

Anyway this link is very useful.

Update:

I implemented the serialization mentioned in the above link, and it increased the file size. In my case the best option will be using -v7 format since it provides the smallest file size, and is also able to save structures and cell arrays that I use a lot.

Community
  • 1
  • 1
ilyas
  • 609
  • 9
  • 25