for-loop never reach the times I need
1 次查看(过去 30 天)
显示 更早的评论
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 个评论
Walter Roberson
2012-6-24
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.
采纳的回答
Hsinho
2012-6-26
2 个评论
Walter Roberson
2012-6-26
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
更多回答(0 个)
另请参阅
类别
在 Help Center 和 File Exchange 中查找有关 Logical 的更多信息
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!