关于 Matlab 中的随机数生成器

About Random Number Generator in Matlab

matlab中的rand函数生成一个0-1之间的随机数,space0.0001。有没有办法把这个 space 加宽,让生成的数字只到小数点后第一位或第二位??感谢您的任何建议。

我了解 Matlab 生成均匀间隔的随机数。如果你想扩大精度步骤,你可以尝试将 rand 乘以某个值 'a' 给你 0.0001*a 间距,然后选择低于 1 的数字。

您可以使用round函数:http://www.mathworks.com/help/matlab/ref/round.html

Y = round(X,2)

Y = round(X,N) rounds to N digits: N > 0: round to N digits to the right of the decimal point. N = 0: round to the nearest integer. N < 0: round to N digits to the left of the decimal point.

您可以使用 randi[0,10^n] 之间生成伪随机整数并除以 10^n:

randTens     = randi([0,10 ])/10;
randHundreds = randi([0,100])/100;
...