Index pairs permutations
Get all possible permutations of x-y index pairs of a matrix
Get all possible permutations of x-y index pairs of a matrix
Cartesian product of two vectors
% get number column and rows of a data matrix
mymatrix = zeros(3,4)
[Nrow,Ncol]=size(mymatrix)
% get all permutations (Cartesian product)
[X,Y] = meshgrid(1:Nrow,1:Ncol)
xy_pairs = [X(:) Y(:)]
1 1
1 2
1 3
1 4
2 1
2 2
2 3
2 4
3 1
3 2
3 3
3 4
% exclude diagonal (1,1) (2,2) .. and inverse pairs
xy_pairs = xy_pairs( xy_pairs(:,1) < xy_pairs(:,2) ,:)
1 2
1 3
1 4
2 3
2 4
3 4