MATLAB爱好者论坛-LabFans.com

MATLAB爱好者论坛-LabFans.com (https://www.labfans.com/bbs/index.php)
-   资料存档 (https://www.labfans.com/bbs/forumdisplay.php?f=72)
-   -   在matlab中打印n个选择k个组合 (https://www.labfans.com/bbs/showthread.php?t=22317)

poster 2019-12-01 22:40

在matlab中打印n个选择k个组合
 
我需要在matlab中创建一个[URL="https://i.stack.imgur.com/pyvg2.png"]算法[/URL] ,该[URL="https://i.stack.imgur.com/pyvg2.png"]算法[/URL]从k集返回n个子集的任意组合。例如,我有一个{1,2,3,4,5}集合,并且我需要此集合中包含的3个数字的任意组合。因此,此函数应返回:

[B][[1、2、3],[1、2、4],[1、2、5],[1、3、4],[1、3、5],[1、4、5],[ 2,3,4],[2,3,5],[2,4,5],[3,4,5]][/B]

我试图自己写它,但是没有成功,我放弃了。它部分起作用,但会产生无限循环。

for i=1:n if(firstTime) lastComb=min //123 firstTime=false else for d=k:-1:1 while(lastComb(:,end) < n-k+d && lastComb(:,end) n-k+d && lastComb(:,end)


所有时间均为北京时间。现在的时间是 19:42

Powered by vBulletin
版权所有 ©2000 - 2025,Jelsoft Enterprises Ltd.