How to create variable in MAT file that is too large to fit in memory?
Show older comments
The new 2011b release provides the matfile object, allowing you to load a portion of a large MAT-file variable using indices. This is useful if the entire variable cannot fit in memory.
But my question is, how can I create such a large variable in a MAT file in the first place, if I cannot construct it entirely in memory first? The save -append option only adds variables to a file; it does not append elements to a variable in the file.
I see that the matfile object allows for partial save (by indices) in the same manner as partial read, so if I could somehow allocate such a large variable (like a zeros() for matfile), then I could write to it piecemeal.
1 Comment
Oleg Komarov
on 7 Sep 2011
Not such a great addition then...
Accepted Answer
More Answers (2)
James Tursa
on 7 Sep 2011
1 vote
You could create the MAT file from scratch in a Fortran or C/C++ program using the published uncompressed MAT file format. E.g., here:
A variable of the desired size doesn't have to exist in memory in order for the MAT file to be written.
the cyclist
on 7 Sep 2011
0 votes
One simple possibility is that the large array was created and saved when it was the only variable in the workspace, but later is loaded when the workspace is littered with other variables, so there is only room for part of it.
2 Comments
Jeff
on 7 Sep 2011
Walter Roberson
on 7 Sep 2011
Or the large array was constructed on a system which had more memory, including possibly a 64 bit MATLAB version for a file being loaded on a 32 bit MATLAB version.
Subnote: if you are planning to use such large matrices, you should probably be saving with -v7.3 as your files might be too large for -v7 . But beware that -v7.3 file performance can be much worse than -v7 file performance (unless they fixed that.)
Categories
Find more on Workspace Variables and MAT Files in Help Center and File Exchange
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!