1
votes

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?

2
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
yeah i am saving all. I need all the variables.ilyas
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
Oh OK. No they are identical.ilyas

2 Answers

3
votes

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.

0
votes

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.