Out of memory when use zeros
1 view (last 30 days)
Show older comments
hi
i have
Out of memory. Type HELP MEMORY for your options.
hen i want to creat a matrix KG
KG=zeros(3*NNOD,3*NNOD);
NNOD= 2000
i use matlab 2014b in windows32
there is another way to create matrix KG or built KG ithout initialise it to zeros
4 Comments
Steven Lord
on 11 Nov 2020
In addition to what others have said, you indicated:
i use matlab 2014b in windows32
A 32-bit version of MATLAB on 32-bit Windows is severely limited in how much memory it can access. If you can switch to a 64-bit version of MATLAB on a 64-bit version of Windows, that may help you out.
Answers (1)
Image Analyst
on 11 Nov 2020
How are you going to use this array? Are you just going to see if the values are 0 or 1? If so, you can use a logical array and use 8 times less memory:
NNOD = 2000
KG = false(3*NNOD, 3*NNOD); % Using false instead of zeros to create a logical matrix.
Alternatively, if it needs to be floating point, because it has values other than 0 and 1, you can cast it to single instead of double. This will cut the memory used by half:
NNOD = 2000
KG = zeros(3*NNOD, 3*NNOD, 'single'); % Using 'single' to make array single precision instead of double precision.
You can also cast it to int32, int16, uint8, or other types depending on how you're going to use it and what you plan on putting into the matrix.
5 Comments
Image Analyst
on 12 Nov 2020
David, I didn't see anyone mentioning logical so I added that. And then I saw that no one had given actual code for 'single', which users usually like so they can click the copy button and don't need to look up in the documentation to figure it out, so I added that code for the user's convenience. I suggest you move your comment down to the official "Answers section" since your comment seems more like an actual answer (and a very good one!) than a comment asking the poster for clarification. We're supposed to comment on the poster's original post when we need to ask questions about it to get them to clarify it or add missing info or files, but otherwise put answers further below in the Answers section.
See Also
Categories
Find more on Logical 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!