Can Matlab randomly generate a combination with groups of varying size?
5 次查看(过去 30 天)
显示 更早的评论
I am quite new with Matlab, is there any buddy have idea how can I generate a combination of numbers with groups of varying size? For example, the number is 1, 2 ,3, 4, 5 ,6, 7 I want to generate a combination with groups like {[1 2],[3 5],[4 6 7]} or {[1],[2],[3],[4],[5],[6],[7]}, or {[1 2 3],[4 5 6],[7]}. Each group can maximumly only have 3 numbers Can any buddy instruct me how to implement this? with great thanks.
0 个评论
采纳的回答
Stephen23
2015-11-15
编辑:Stephen23
2015-11-15
The problem is essentially the random partitioning of a vector. Partitioning is inherently a recursive operation, for which you will find several algorithms online. Typically these algorithms generate all partitions of an integer or set, but you may be able to adapt an algorithm to return just one (random) partition.
A good place to start would be to try out Matt Fig's excellent FEX submission partitions:
You could use Matt Fig's submission to generate all partitions, select those with length three or less, and then randomly select one of those.
更多回答(0 个)
另请参阅
类别
在 Help Center 和 File Exchange 中查找有关 Creating and Concatenating Matrices 的更多信息
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!