how to generate random integer number in a fixed range in MATLAB, like between 1 to 10

조회 수: 889 (최근 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
Sean de Wolski 2013년 1월 10일
doc randi
and simple example:
randi([1 10],40)

추가 답변 (2개)

Jan
Jan 2013년 1월 10일
If repetitions are not wanted:
c = randperm(10);
  댓글 수: 7
Nitish Jha
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
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.

카테고리

Help CenterFile Exchange에서 Function Creation에 대해 자세히 알아보기

태그

Community Treasure Hunt

Find the treasures in MATLAB Central and discover how the community can help you!

Start Hunting!

Translated by