From: Chan Chun K Chan on
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
"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
"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
"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
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.