Quantcast
Channel: MATLAB Central Newsreader Recent Posts
Viewing all articles
Browse latest Browse all 19628

Re: Out of Memory when creating several large matrix

$
0
0


"LEI Zhang" <sesime@gmail.com> wrote in message
news:ka5djc$s0r$1@newscl01ah.mathworks.com...
> Hello, I am creating 5 large matrix like this:
>
> a=zeros(1000,1000,1000)
> b=zeros(1000,1000,1000)
> c=zeros(1000,1000,1000)
> d=zeros(1000,1000,1000)
> e=zeros(1000,1000,1000)
>
> however, when creating matrix d, it output error "out of memory"

In MATLAB, matrices are 2-D. If you have a 3-D or higher dimension variable,
it's an array.

> My server is 64 bit windows 7 with 12 GB memory, Matlab is 64 bit too. I
> don't think there should be any problem with my physical memory.
>
> What can I do for this?

Nasser already commented on this. Memory fragmentation may also contribute
to your inability to create all five large arrays.

> I don't need those matrix be double precision, some can be single, some
> can be int8, so I can convert those matrix after initialization.

Don't create a double and then convert. Create the matrix in the smaller
data type to begin with.

a = zeros(1000, 1000, 1000, 'single');
b = zeros(1000, 1000, 1000, 'int8');

> But I hope, I can find a deep solution for my problem, because I don't
> think those 5 matrix eat up all of memory.

They do.

>> numberOfElements = 1000^3;
>> sizeInBytes = numberOfElements*8;
>> gb = sizeInBytes/(1024^3)

gb =

    7.4506

Creating the matrix initially as a single or int8 will change the 8 in the
computation of sizeInBytes.

--
Steve Lord
slord@mathworks.com
To contact Technical Support use the Contact Us link on
http://www.mathworks.com

Viewing all articles
Browse latest Browse all 19628

Trending Articles