creating a variable to use for grouping data
1 次查看(过去 30 天)
显示 更早的评论
I want to create a variable (a column vector) with a specific length (8000), containing values 1 to 10 randomly assigned and with a specific average repetition of each number (say 800). How to do this?
0 个评论
采纳的回答
Walter Roberson
2012-4-20
If the number of repetitions is to be exact:
t = repmat(1:10.', 800, 1);
t(randperm(length(t)))
If the repetitions need not be exact:
1 + floor(10 * rand(8000,1))
2 个评论
Walter Roberson
2012-4-20
Opps, I had an extra layer of repmat() on the first solution! I have edited.
更多回答(0 个)
另请参阅
产品
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!