# num2cell out of memory

7 ビュー (過去 30 日間)
Jorge Aarón Morán Holguín 2019 年 12 月 23 日
コメント済み: Sharif Khalil 2021 年 1 月 2 日
I have a huge dataset that when loaded in the workbench it turns into a 67x20838735 double. Then problem is that when I try to convert it into cell array I get the following message: Out of memory. Type "help memory" for your options.
inputs = num2cell(inputs)
I trien to find a way to solve this problem with loops, but I don't find any way to succeed.

サインインしてコメントする。

### 回答 (2 件)

Uerm 2019 年 12 月 23 日
Hi,
You are working with quite a large variable. I have tried the following
n = rand(67,20838735);
When running whos it says that the variable n uses a bit more than 11 GB of memory. That is more than what most of the normal computers/laptops have :) I think that your computer simply does not have enough memory (RAM). How much RAM does your computer have?
There are some things that you can try.
1) Before converting to cell arrays, you can try to convert the variable from double to single:
n = single(n);
This will make the variable n use half of the memory it did when it was a double.
2) Normally, MATLAB limits the maximum array size to a percentage of the RAM of the computer. You can get rid of this limit by this path:
Click the Home tab --> Click Preferences --> Choose Workspace in the left menu --> On the bottom of the page there is a box saying "Limit the maximum array size to a percentage of RAM". Make sure that this box is empty --> Click Apply and OK.
I suggest that you start with step 2. If that does not work, supply with step 1.
If none of the above works, you can make MATLAB use virtual memory. You can read more about it here:
The tradeoff of using virtual memory is the computation speed!
##### 1 件のコメント表示非表示 なし
Jorge Aarón Morán Holguín 2019 年 12 月 23 日
Hello,
My computes has a total 96GB of memory.
>> memory
Maximum possible array: 45018 MB (4.720e+10 bytes) *
Memory available for all arrays: 45018 MB (4.720e+10 bytes) *
Memory used by MATLAB: 93519 MB (9.806e+10 bytes)
Physical Memory (RAM): 96922 MB (1.016e+11 bytes)
* Limited by System Memory (physical + swap file) available.
I have tried both options combined and the problem remains.

サインインしてコメントする。

per isakson 2019 年 12 月 24 日

Why do you want to convert the numerical matrix to a cell array? It requires an enormous amount of memory for overhead.
>> clearvars
>> num = (1:12);
>> cac = num2cell( num );
>> whos num cac
Name Size Bytes Class Attributes
cac 1x12 1440 cell
num 1x12 96 double
I think the resulting cell array will need (1440/96)*11 GB. That's twice as much as your ram.
##### 3 件のコメント表示非表示 2 件の古いコメント
Sharif Khalil 2021 年 1 月 2 日
Hi Jorge,
Did you get an answer to your problem?

サインインしてコメントする。

R2019a

### Community Treasure Hunt

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

Start Hunting!

Translated by