how to generate random integer number in a fixed range in MATLAB, like between 1 to 10
521 次查看(过去 30 天)
显示 更早的评论
i want to generate random number between 1 to 10 answer like: 7 4 1 8 5 2 10 6 9 3
采纳的回答
Sean de Wolski
2013-1-10
doc randi
and simple example:
randi([1 10],40)
1 个评论
Hassaan
2024-2-17
If repititions are not required:
c = randperm(20);
disp(c)
更多回答(2 个)
Jan
2013-1-10
If repetitions are not wanted:
c = randperm(10);
7 个评论
Nitish Jha
2021-3-16
Hii...Prioduyti and others...How to use this code with a component used in simulink .I want to use randi function with a component of matlab simulink (lead screw)..how to link this function with that....Please guide.
Ruochen
2019-9-26
Use randsample
if the range is 1 to n:
y = randsample(n,k) returns k values sampled uniformly at random, without replacement, from the integers 1 to n.
if the range is say 8 to 23, choose 6 randon mumbers
population = 8:23;
y = randsample(population,6)
y = randsample(population,k) returns a vector of k values sampled uniformly at random, without replacement, from the values in the vector population.
0 个评论
另请参阅
类别
在 Help Center 和 File Exchange 中查找有关 Function Creation 的更多信息
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!