Clear Filters
Clear Filters

Memory overload with dec2bin

1 view (last 30 days)
andreas
andreas on 8 Jul 2013
If i try to run this command:
M = dec2bin(0:2^21-1, 21);
I get the following error: "Error using * Out of memory. Type HELP MEMORY for your options."
When trying to run it with 2^20 it still works.
Is there a way to work around that error?
PS: I will have to work with that data later on. Is that even possible?

Accepted Answer

Jan
Jan on 8 Jul 2013
This creates the vector 0:2^21-1 as double array at first, which requires 16.777.216 Bytes. Then for each of these values 21 characters a 2 Byte are created, which means additional 88.080.384 Bytes. If this exhausts your memory already, you simply do not have enough RAM. Then either use something like FEX: VChooseKRO to create the output as UINT8 array, which occupies the half size only:
M = VChooseKRO(uint8([0, 1]), 21);
But a much better idea would be to run a 64-bit Matlab version on a 64-bit operating system an installing some more GB of RAM.
  1 Comment
andreas
andreas on 10 Jul 2013
Thank you. I went to another PC and it worked out very well.

Sign in to comment.

More Answers (0)

Community Treasure Hunt

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

Start Hunting!