Info
This question is locked. 请重新打开它进行编辑或回答。
Making random to work like randi
6 次查看(过去 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!