Re: [問題] 想請問分組問題已回收

看板MATLAB作者 (神無月 孝臣)時間17年前 (2008/12/23 20:03), 編輯推噓0(000)
留言0則, 0人參與, 最新討論串3/3 (看更多)
※ 引述《victer0327 (victory)》之銘言: : 假設我有 Org = 5*13 的矩陣 : 其中有A B C D E 五個members : -------------------- : A | | : -------------------- : B | | : -------------------- : C | | : -------------------- : D | | : -------------------- : E | | : -------------------- : 而我要隨機將他們分組(組數是隨機的,所以有可能全部一組;也可能一人一組) : -------------------- -------------------- -------------------- : A | | B | | C | | : -------------------- -------------------- -------------------- : E | | D | | : -------------------- ------------------- : 請問我該如何撰寫? 這個做一般的組合就好啦 [ A1 A2 A3 A4 A5 ] = ndgrid( [0:5] , [0:5] , [0:5] , [0:5] , [0:5] ) ; A = unique(sort([A1(:),A2(:),A3(:),A4(:),A5(:)],2),'rows') ; 這樣全部的組合就出來了 要用的時候當做index用即可 先把ABCDE存成一個大矩陣假設叫做AA index = randperm( size( A , 1 ) ) ; AA( A( index( 隨便一個數字 ) ,find(A( index( 跟前面一樣的數字 ) , : ) ) ) , : ) 這樣叫出來用即可 -- Deserves death! I daresay he does. Many that live deserve death. And some die that deserve life. Can you give that to them? Then be not too eager to deal out death in the name of justice, fearing for your own safty. Even the wise cannot see all ends. Gandalf to Frodo -- ※ 發信站: 批踢踢實業坊(ptt.cc) ◆ From: 125.233.241.18
文章代碼(AID): #19KDEGB9 (MATLAB)
文章代碼(AID): #19KDEGB9 (MATLAB)