matlab中如何产生10个1--4之间的随机整数?

2025-01-15 13:11:49
推荐回答(3个)
回答1:

>> a=rand(1,10);%生成1行10列共十个0到1之间的随机小数
>> b=a*4+1;%将随机小数映射到1到5(不含5)之间
>> c=floor(b)%只取整数部分

将以上程序拷入运行即可

回答2:

matlab中如何产生9个随机数,和为定值M;并且M能由输入确定。能给个程序嘛M=300; a=randint(1,9,[1 5]) % [1 10]为取值范围 M*a/(sum(a

回答3:

randi([1 4],10,1);
Use the randi function (instead of rand) to generate 10 random integers from the uniform distribution between 1 and 4. I hope it is useful to you。