Q: How to store HUGE matrices?
So your RAM is no longer enough? It might help to use shorter datatypes (SINGLE, INT32, INT16, INT8) that use (4,4,2,1) bytes per element, compared to 8 bytes for double (PC platform):» A=magic(100);whos Name Size Bytes Class A 100x100 80000 double array Grand total is 10000 elements using 80000 bytes » A=int8(A);whos Name Size Bytes Class A 100x100 10000 int8 array Grand total is 10000 elements using 10000 bytesThere are two caveats, though. First, no arithmetic operations are defined for non-double classes:
» A(1)+A(2) ??? Error using ==> + Function '+' not defined for variables of class 'int8'.Reshaping, subscripting and transposing still work, and you can always convert a subset of your matrix back to double for computations.
A=UINT8(zeros(1e6,1));This, however, creates a full-size double array first, defying the whole purpose (it is slow and it might not fit at all)! Here is a couple of workarounds (© Steve Eddins, eddins@mathworks.com):
A(1e6,1) = int8(0); % assuming "A" has not yet been defined - or - A = repmat(int8(0),1e6,1);