Randomise vector numbers to maximum variance
11 次查看(过去 30 天)
显示 更早的评论
I have a vector that contains numbers 1, 0 and 10. In partcular, I have 100 times the 1, 400 times the 0 and 20 times the 10.
Is there any function or any way to shuffle the numbers to the maximum variance regarding their repetition? Namely, I want to shuffle them in a way to minimise their sequential repeatibility, so a to achive the low number of times that I get 1,1 or 0,0 or 10,10 in my vector?
Thank you so much in advance!
采纳的回答
Bruno Luong
2022-9-9
A = repmat([10 repmat([repmat(0, 1, 2), 1 repmat(0, 1, 2)], 1, 5)], 1, 20);
10 个评论
Bruno Luong
2022-9-9
This is a method for generic case
v=[0 1 10];
n=[400 100 20];
A = shuffle(v, n)
function A = shuffle(v, n)
[m,i] = maxk(n,2);
mm = min(m);
if mm > 0
n(i) = n(i)-mm;
A = [repmat(v(i), 1, mm), shuffle(v, n)];
else
[mm,j] = max(m);
A = repmat(v(i(j)), 1, mm);
end
end
更多回答(0 个)
另请参阅
类别
在 Help Center 和 File Exchange 中查找有关 Descriptive Statistics and Visualization 的更多信息
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!