From: Chan Chun K Chan on 4 Apr 2010 02:48 Hi! I have a problem here and need some help: Suppose there's a m*n (m around 10) matrix, how to choose a random 2 rows from the matrix and exhaust all combination? And also to note down which two rows were used for each operation? Thanks in advance!
From: Cagri on 4 Apr 2010 04:05 "Chan Chun K Chan" <asdf(a)yahoo.com> wrote in message <hp9cn5$ped$1(a)fred.mathworks.com>... > Hi! I have a problem here and need some help: > Suppose there's a m*n (m around 10) matrix, how to choose a random 2 rows from the matrix and exhaust all combination? And also to note down which two rows were used for each operation? Thanks in advance! There may be a shorter way with a built-in method of Matlab, but this code just works fine, too: --------------------------------------------------------------------------------------- [m, n] = size(X); % m data points, n dimensions randomPoints = []; for i=1:2 index = random('unid', m); % Pick the index at random. randomPoints(i,:) = X(index,:); % Add random point. X(index,:) = []; % Delete selected row. m = m-1; end ---------------------------------------------------------------------------------------
From: us on 4 Apr 2010 04:18 "Chan Chun K Chan" <asdf(a)yahoo.com> wrote in message <hp9cn5$ped$1(a)fred.mathworks.com>... > Hi! I have a problem here and need some help: > Suppose there's a m*n (m around 10) matrix, how to choose a random 2 rows from the matrix and exhaust all combination? And also to note down which two rows were used for each operation? Thanks in advance! a hint: help randperm; us
From: Cagri on 4 Apr 2010 05:26 "Chan Chun K Chan" <asdf(a)yahoo.com> wrote in message <hp9cn5$ped$1(a)fred.mathworks.com>... > Hi! I have a problem here and need some help: > Suppose there's a m*n (m around 10) matrix, how to choose a random 2 rows from the matrix and exhaust all combination? And also to note down which two rows were used for each operation? Thanks in advance! There may be a shorter way with a built-in method of Matlab, but this code just works fine, too: --------------------------------------------------------------------------------------- [m, n] = size(X); % m data points, n dimensions randomPoints = []; for i=1:2 index = random('unid', m); % Pick the index at random. randomPoints(i,:) = X(index,:); % Add random point. X(index,:) = []; % Delete selected row. m = m-1; end ---------------------------------------------------------------------------------------
From: Chan Chun K Chan on 4 Apr 2010 06:13 Thanks for the help so far. Is there a way to exhaust all possible combination? my goal is not to just stop at selecting 2 rows, but to try out all combination. It would also be great if no row is deleted during the process. Much appreciated.
|
Next
|
Last
Pages: 1 2 3 Prev: Threshold's calculation in wentropy Next: how to set folder for compression |