Info
This question is locked. 편집하거나 답변을 올리려면 질문을 다시 여십시오.
Making random to work like randi
조회 수: 5 (최근 30일)
이전 댓글 표시
I have this code
idx = randi(N_clusters,N_clusters,1);
but I want to use the random function to achieve the same output. I do not get into why I want to use the random function but it is important for my work flow. So then I tried
pd = makedist('DiscreteUniform','Lower',1,'Upper',N_clusters);
idx = random(pd,N_clusters,1);
But MATLAB gives an error that "DiscreteUniform" is not recognized. What is my best alternative usinf the random function, if I stll can.
댓글 수: 0
채택된 답변
Paul
2025년 8월 4일
N_clusters = 10;
rng('default');
idx = randi(N_clusters,N_clusters,1)
rng('default');
random('Discrete Uniform',N_clusters,N_clusters,1)
댓글 수: 1
추가 답변 (1개)
Matt J
2025년 8월 4일
편집: Matt J
2025년 8월 4일
idx = floor( (N_clusters-1)*rand(N_clusters,1) )+1
This question is locked.
참고 항목
카테고리
Help Center 및 File Exchange에서 Random Number Generation에 대해 자세히 알아보기
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!