Out of Memory error when removing columns of a big matrix .
1 view (last 30 days)
Show older comments
Hello,
I have constructed a big matrix A in MATLAB ( 120000 x 120000) without any issue. However, I am getting out-of-memory error when i try to remove few columns of this matrix using A(:,1:10)=[]. I am guessing, MATLAB is creating a temporary matrix while doing this operation and thats why i am getting an error.
Is there a way to overcome this issue?
1 Comment
Walter Roberson
on 24 Jan 2020
Yes, MATLAB does create a temporary matrix for this purpose.
I do not know if there is any alternative, even using mex; I do not know if there is a realloc() equivalent that can give back trailing memory.
It would possibly be easier if you were to fill in the shortened matrix with 0 or NaN so that the columns were compacted but the array stayed the same size.
Answers (1)
James Tursa
on 24 Jan 2020
Edited: James Tursa
on 24 Jan 2020
What are you doing with the matrix A downstream in your code? Even if the column removal worked, seems like you still might have problems downstream when using A in a calculation which would create another large variable.
There is no easy mex solution for this either, since you can't set the data pointer of a variable to point to the interior of an allocated memory block legally. The only workaround I can think of is this FEX mex submission which uses unofficial hacks to point at the interior of a variable without a data copy:
0 Comments
See Also
Categories
Find more on Matrix Indexing 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!