Out of memory when use zeros

2 Ansichten (letzte 30 Tage)
alize beemiel
alize beemiel am 11 Nov. 2020
Kommentiert: Image Analyst am 12 Nov. 2020
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 Kommentare
Steven Lord
Steven Lord am 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.
alize beemiel
alize beemiel am 12 Nov. 2020
thank s for your advice
waiting for switch to 64 bit
i used
KG = zeros(3*NNOD, 3*NNOD, 'single'); for now
and its work
thank you

Melden Sie sich an, um zu kommentieren.

Antworten (1)

Image Analyst
Image Analyst am 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 Kommentare
James Tursa
James Tursa am 12 Nov. 2020
... which is why I wish we could vote for comments.
Image Analyst
Image Analyst am 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.

Melden Sie sich an, um zu kommentieren.

Kategorien

Mehr zu Loops and Conditional Statements finden Sie in Help Center und File Exchange

Community Treasure Hunt

Find the treasures in MATLAB Central and discover how the community can help you!

Start Hunting!

Translated by