mardi 24 novembre 2015

MATLAB - Best way of creating 2d array of unique pairs?

What is the best way of creating a 10x2 matrix in matlab where each element is a random int between 1-5, and so that there are only unique pairs of elements in this array? I know randperm can give a me random unique numbers, but Im not sure if its possible to use randperm to give unique pairs? The only other way I can think of is using:

randi([1 5], 10, 2);

In a loop with an if statement checking whether all pairs are unique. An example of the data I would like would be something like:

4 5
1 3
2 2
1 4
3 3
5 1
5 5
2 1
3 1
4 3

Note: the order of the elements does not matter for example, both 4, 5 and 5, 4 would be valid.




Aucun commentaire:

Enregistrer un commentaire