hi i receive this message in matlab when i run a monte carlo probllem
Requested 1000000x10000 (74.5GB) array exceeds maximum array
size preference. Creation of arrays greater than this limit
may take a long time and cause MATLAB to become
unresponsive. See array size limit or preference panel for
more information.
Error in Z12R2the (line 14)
y=0.5.*(yv-yh)+0.5.*(yv+yh).*cos(2.*PSI);
Error in impedance_antennaR_new_2d (line 82)
fn=Z12R2the(r,PSI);
i can change this preference? i want to run the MC with 1e6 randon mumbers
thank you
George

2 Comments

There are various ways around a size limit. Why not loop through a number of times? Additional code would be helpful to make suggestions.
Hi i use the following line
n=1e5;
PSI=random('unif',psi1,psi2,[1,n]);
pd = makedist('Normal', 'mu', h0, 'sigma', st);
t = truncate(pd,h1,h2);
r = random(t,1e4,1);
when i change the tandom numbers form 1e4 -> 1e5 i receive the message about memory
George

Sign in to comment.

 Accepted Answer

PSI=random('unif',psi1,psi2,[1,n]);
That is a row vector
r = random(t,1e4,1);
That is a column vector
fn=Z12R2the(r,PSI);
You are passing in the column vector and the row vector
y=0.5.*(yv-yh)+0.5.*(yv+yh).*cos(2.*PSI);
The 2.*PSI part will be the row vector.
Without seeing more code, we cannot be certain, but the implication is that most likely yv and yv are a column vector the size of r.
When you try to combine a column vector with 1e5 elements, with a row vector with 1e4 elements, that is generally legal in MATLAB, and MATLAB would try to create a 1e5 x 1e4 array that contained all combinations -- like
r1c1 r1c2 r1c3 r1c4 .... r1c10000
r2c1 r2c2 r2c3 r2c4 .... r2c10000
...
r100000c1 .............. r100000c10000
That would require 1e5 * 1e4 * 8 bytes, which is almost certainly a lot more than you have on your system.
If you did manage to create an array that size, then MATLAB would immediately need to create another array that size in order to finish the addition part of the assignment.
If you have enough free space, it is probably possible to configure your MATLAB and your operating system to permit MATLAB to go ahead and create arrays that large. However, the resulting operations would be quite slow, as it would write a lot of information to disk.
As your variables are random, it is unlikely that you need to have all of those in memory at one time. You would be better off running with 1e4 r values and accumulating statistics for 10 of those runs.

5 Comments

yes but this erroe appear in the case of gauss distribution
when i use unform distribution for two variable with 1e6 random number
the code running wihtout any problem
it is possible to find truncated gauss with row vector?
Truncated gaussian as a row vector is a trivial change to what you had before.
pd = makedist('Normal', 'mu', h0, 'sigma', st);
t = truncate(pd,h1,h2);
r = random(t,1,1e4);
YES work with 1e6 random number !!
i change the column vector with column and the code is runing with 1e6 random number
thank !

Sign in to comment.

More Answers (1)

Jan
Jan on 19 Aug 2021
If you request 74.5GB of RAM for a matrix, care for having this size of memory plus some head room. On a 160 GB RAM machine, the code will run.
Did you follow the advice in the error message already:
See array size limit or preference panel for more information.
?

5 Comments

How i can change the size array?
Preferences -> MATLAB -> Workspace -> Limit the maximum array size to a percentage of RAM (untick this and Save the change)
If you are using Windows 10 (or any Windows) you will also need to configure larger page files; see https://www.thewindowsclub.com/increase-page-file-size-virtual-memory-windows
Your particular code will require at least twice as much temporary memory as the largest sustained array, so if your code is currently complaining that it cannot create a 75 gigabyte array, then you must configure your swap space to at least 150 gigabytes.
I find one page from 2018 that claims that the limit on Windows 10 is 4 times the amount of physical RAM you have, but that might have been the limit for an older version of Windows.
WARNING
Using that much swap memory on your system will be very 👏🏻 very 👏🏻 very 👏🏻 slow. For days. Maybe weeks.
So slow that any given keystroke you type might take half an hour to be registered by the computer.
thank it is better choise to use 1e5 OR 1e4 RANDOM NUMBER
Divide the run up into batches that each fit into memory, and accumulate statistics as necessary.
I dont know how can i make this

Sign in to comment.

Categories

Find more on Software Development Tools in Help Center and File Exchange

Products

Release

R2019a

Tags

Community Treasure Hunt

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

Start Hunting!