1.
rand
产生随机数
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.
随机数发生器是有状态的,可以通过保存函数获取当前的状态,这样下次的时候就可以使用当前状态得到相同的随机数。help rand 有个例子:
Example 4: Save the settings for the random number generator used by rand, RANDI, and RANDN, generate 5 values from rand, restore the settings, and repeat those values.
s = rng
u1 = rand(1,5)
rng(s);
u2 = rand(1,5) % contains exactly the same values as u1
当然,我们使用别人的代码时候,有时候没法使用rng,就需要统一状态,所以就需要rand('state',0):这个是都恢复为初始状态。
>> rand('state',0);
>> rand(3,1)
ans =
0.9501
0.2311
0.6068
>> rand('state',0);
>> rand(3,1)
ans =
0.9501
0.2311
0.6068
2 Linux 后台运行Matlab程序
nohup
matlab < inputscript.m > run.log