Info
This question is locked. Riaprila per modificarla o per rispondere.
Making random to work like randi
5 visualizzazioni (ultimi 30 giorni)
Mostra commenti meno recenti
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 Commenti
Risposta accettata
Paul
il 4 Ago 2025
N_clusters = 10;
rng('default');
idx = randi(N_clusters,N_clusters,1)
rng('default');
random('Discrete Uniform',N_clusters,N_clusters,1)
1 Commento
Più risposte (1)
Matt J
il 4 Ago 2025
Modificato: Matt J
il 4 Ago 2025
idx = floor( (N_clusters-1)*rand(N_clusters,1) )+1
This question is locked.
Vedere anche
Categorie
Scopri di più su Random Number Generation in Help Center e File Exchange
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!