Re: [問題] 想請問分組問題已回收
※ 引述《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
討論串 (同標題文章)
本文引述了以下文章的的內容:
完整討論串 (本文為第 3 之 3 篇):
MATLAB 近期熱門文章
PTT數位生活區 即時熱門文章