如何在MATLAB中从总数N中获得K个项目的所有可能组合 [英] How to get all possible combinations of K items from a total of N in MATLAB
本文介绍了如何在MATLAB中从总数N中获得K个项目的所有可能组合的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!
问题描述
例如,如果[1,2,3,4,5,6]
是向量,则一次3个项目的所有可能组合为
For e.g., if [1,2,3,4,5,6]
is a vector, then all possible combinations of 3 items at a time is
4 5 6
3 5 6
3 4 6
3 4 5
2 5 6
2 4 6
2 4 5
2 3 6
2 3 5
2 3 4
1 5 6
1 4 6
1 4 5
1 3 6
1 3 5
1 3 4
1 2 6
1 2 5
1 2 4
1 2 3
如何在MATLAB中找到它?
How do I find this in MATLAB?
推荐答案
尝试一下链接.基本上,您只需要键入c = combnk(1:6,3)
.希望对您有所帮助.
Try this link. Basically you just need to type c = combnk(1:6,3)
. Hope it helps.
我提出的建议和@nash的combntns
之间的区别是命令所在的工具箱.combnk
在统计信息"工具箱中,而combntns
在映射工具箱"中.
The difference between what I proposed and @nash 's combntns
is the toolbox that the commands are in. combnk
is in the Statistics Toolbox, while combntns
is in the Mapping Toolbox.
这篇关于如何在MATLAB中从总数N中获得K个项目的所有可能组合的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!
查看全文