for-loop never reach the times I need
1 visualización (últimos 30 días)
Mostrar comentarios más antiguos
Hi,
I have a 130-by-2000 matrix. I need to do two major steps on this matrix. In the first steps, indices of this matrix were randomly selected in a way that only one element in each column was selected. In the second steps, the value of selected index of this 130-by-2000 matrix was randomly changed within a range. The whole procedure need to repeat for 2.1e7 times. I use a for-loop ( for n=1:2.1e7) to repeat 2.1e7 times. I put a tic and toc to count the time every 1e5 times.
The problem is that the time always stops counting on 16700000 times but it still continues simulation till n always ends on 16777216 times. It never reach 2.1e7 times I want.
16777216 is exactly 8^8 or 2^24. WHY?
The memory should be sufficient. I use "whos" to sum the total used memory and it is 5698696 bytes. All variables are in single precision. My laptop is Windows 7 with 8GB memory and CPU is intel Core i7.
Could someone tell me what causes this problem? Why can the for-loop be limited?
Could it be limited by pseudorandom number generating?
Quoted from "Help": The simplest way to generate arrays of random numbers is to use rand, randn, or randi. These functions ALL rely on the SAME stream of uniform random numbers, known as the GLOBAL stream.
Do the amount of pseudorandom numbers in my script already exceed this "global stream" since all rand functions rely on the same stream? I wonder how many numbers can be generated in this global stream?
3 comentarios
Walter Roberson
el 24 de Jun. de 2012
http://www.mathworks.com/help/techdoc/ref/randstream.list.html
The "period" listed there is the number of random numbers that can be generated before the sequence repeats.
Respuesta aceptada
Hsinho
el 26 de Jun. de 2012
2 comentarios
Walter Roberson
el 26 de Jun. de 2012
IEEE 754 single precision has only 23 bits stored for the fraction, plus it has 1 "hidden bit", for a total of 24 bits of accuracy. Which corresponds to 2^24.
http://steve.hollasch.net/cgindex/coding/ieeefloat.html
Más respuestas (0)
Ver también
Categorías
Más información sobre Logical en Help Center y File Exchange.
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!