From: Jan Simon on
Dear Chan Chun K Chan!

> 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?

What about this:
m = repmat(1:10, 10, 1);
mT = transpose(m);
Index = [m(:), mT(:)];
Index = Index(randperm(size(Index, 1)), :);

Now Index(i, 1) and Index(i,2) are two different row indices, Index is shuffled randomly and exhausts all combinations.

Are you sure that you want combinations, so a row can be chosen twice?
If you want to avoid repetitions, you could use several tools from the FEX:
VChooseKO http://www.mathworks.com/matlabcentral/fileexchange/26242
or
Combinator http://www.mathworks.com/matlabcentral/fileexchange/24325

E.g.:
Index = VChooseKO(1:m, 2); % Or VChooseKRO etc
Index = Index(randperm(size(Index, 1)), :);

Good luck, Jan
From: Chan Chun K Chan on
thanks! that's really helpful.

Just a bit of exploration here, suppose when choosing this combination of two without repeatition, i also want to avoid certain pairs, how should it be done?
From: Jan Simon on
Dear Chan!

> Just a bit of exploration here, suppose when choosing this combination of two without repeatition, i also want to avoid certain pairs, how should it be done?

If you have a M = [m x 2] matrix of indices and want to exclude the index pairs in P = [p x 2], use:
exclude = ismember(P, M, 'rows');
M(exclude, :) = [];

Jan