How can i create a sequence that every symbol has the same probability as the others?
Show older comments
How can i create a sequence that contains the symbols 0 , 1 , 2 , 3 with the same probability 1/4?
For example i created a sequence with 2 symbols 0 , 1 like this :
Seq = randn(1,N)<0.5 %N= length of the seq and each symbol has 1/2 probability
But i am confused about the 4 symbols any help?
Accepted Answer
More Answers (1)
Image Analyst
on 14 Jun 2020
Try repelem() and randperm():
numPoints = 1000 % Multiple of 4
v = [0,1,2,3];
n = numPoints / length(v)
vec = repelem(v, n)
randomOrder = randperm(length(vec))
% Scramble them up.
vec = vec(randomOrder);
% Double check
for k = 1 : length(v)
count = sum(vec == v(k));
fprintf('%d shows up %d times.\n', v(k), count);
end
You'll see from the double check:
0 shows up 250 times.
1 shows up 250 times.
2 shows up 250 times.
3 shows up 250 times.
And the numbers will be randomly placed in the vector.
Categories
Find more on Descriptive Statistics in Help Center and File Exchange
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!