RAND('state',0) resets the generator to its initial state.
RAND('state',J), for integer J, resets the generator to its J-th state.
RAND('state',J) and RAND('state',S) cause the MATLAB 5 generator to be used.
help 里面解释
rand('state',s)Resets the state to s.
rand('state',0)Resets the generator to its initial state.
rand('state',j)For integer j, resets the generator to its j-th state.
用法:
(一)rand('state',s)表示随机产生数的状态state,一般情况下不用指定状态。但是有的书籍作者为了让读者能够看到和他书本的同样结果,采用了设置state,rand('state',0)。作用在于如果指定状态,产生随机结果就相同了。
(二)因为每次rand产生的随机数都不一样,在产生之后,为了得到与前面某个状态相同的结果,用这个函数来产生该相同的随机数
如:>> a=rand(3,1)
a =
0.4565
0.0185
0.8214
>> a=rand(3,1)
a =
0.4447
0.6154
0.7919
>> a=rand(3,1)
a =
0.9218
0.7382
0.1763
而
>> rand('state',0)
>> a=rand(3,1)
a =
0.9501
0.2311
0.6068
>> rand('state',0)
>> a=rand(3,1)
a =
0.9501
0.2311
0.6068
>> rand('state',0)
>> a=rand(3,1)
a =
0.9501
0.2311
0.6068