Random numbers and storing from 1 -5
Mostra commenti meno recenti
Hi, Trying to create a random number gen from 1-5 and store into an array. I want the random numbers to generate 600 times giving me an 100 random 1's,2's,3's,4's and 5's. I keep getting size issues of left and right, anyone able to help? I should end up with 600 random distributions of 1-5 but it stops on the first loop with "Unable to perform assignment because the indices on the left side are not compatible with the size of the right side."
Thanks in advance
x=[];
s = 600;
y = [];
for i=1:1:s
y(i)=randperm(5);
y(i) = transpose(y(i));
x = vertcat(x,y(i));
end
Risposta accettata
Più risposte (1)
David Hill
il 7 Feb 2021
y=zeros(5,600);
for k=1:600
y(:,k)=randperm(5);
end
1 Commento
BionicP
il 7 Feb 2021
Categorie
Scopri di più su Loops and Conditional Statements in Centro assistenza e File Exchange
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!