I found this solution by @Lambdageek to the problem of generating pairs of the elements of a vector in Matlab:
[p,q] = meshgrid(vec1, vec2);
pairs = [p(:) q(:)];
However I want to generate unique pairs from the elements of a vector, let's say [1 2 3]. [1 2] and [2 1] I would consider as duplicates of the same pair and I want to ignore the order of the pair elements.
1 2
1 3
2 1
2 3
3 1
3 2
should reduce to:
1 2
1 3
2 3
Does anyone know an elegant solution to this? Thanks!