Asked by manishika rawat
on 18 Nov 2019 at 12:25

Hi, I am working in code that generates large array values which increases with every iteration of monte carlo simulation. To get accurate result, I need to run the code for large iteration values. However, somehere whlike running, the code stops working stating "out of memory". At the end of the loop I need to perform some arithmatic operation on the values of the array generated. Can you please help me on how can I work with large arrays?

Answer by Walter Roberson
on 19 Nov 2019 at 5:51

It is not possible to tell MATLAB to store variables on disk, at least not in the way you are describing.

You can tell your system to increase your available swap space, and your operating system will then automatically swap to and from memory. However, this tends to be slow.

You might be able to convert your cell array entries into tall() arrays and convolve those. Remember, though, that your thesis is that your convolved arrays are too big for memory, so the final result is probably going to be too big for memory. And then what do you do with it?

manishika rawat
on 19 Nov 2019 at 7:21

Walter Roberson
on 19 Nov 2019 at 9:16

You convert the individual cell arrays into tall arrays. When you convolve the tall arrays, the result will be a tall array, and MATLAB would automatically manage the RAM and disk use for that. Leave the result of the first step as a tall array and convolve with the next cell-turned-into-tall-array, and MATLAB will manage the RAM and disk use for that operation, and so on.

As long as the cell array elements fit into memory long enough to build tall arrays from them, then the convolution of them would not need to fit into memory.

manishika rawat
on 19 Nov 2019 at 10:39

Sign in to comment.

Opportunities for recent engineering grads.

Apply Today
## 3 Comments

## KALYAN ACHARJYA (view profile)

## Direct link to this comment

https://www.mathworks.com/matlabcentral/answers/491690-to-do-arithmetic-operations-with-large-arrays-going-out-of-memory-space#comment_768478

## James Tursa (view profile)

## Direct link to this comment

https://www.mathworks.com/matlabcentral/answers/491690-to-do-arithmetic-operations-with-large-arrays-going-out-of-memory-space#comment_768589

## Stephen Cobeldick (view profile)

## Direct link to this comment

https://www.mathworks.com/matlabcentral/answers/491690-to-do-arithmetic-operations-with-large-arrays-going-out-of-memory-space#comment_768844

Sign in to comment.