# could anyone help me how to randomly pair two numbers in each pair.

1 vue (au cours des 30 derniers jours)
jaah navi le 9 Nov 2021
Commenté : jaah navi le 9 Nov 2021
A=[1:12]
now I want to pair two numbers randomly in each pair as [ 1 3] [ 2 6] [7 9] .....
##### 4 commentairesAfficher 2 commentaires plus anciensMasquer 2 commentaires plus anciens
Mathieu NOE le 9 Nov 2021
almost there
just add reshape and you're done
N = 12;
a = randperm(N)
b = reshape(a,N/2,2)
a =
6 3 11 7 8 5 1 2 4 9 10 12
b =
6 1
3 2
11 4
7 9
8 10
5 12
jaah navi le 9 Nov 2021
Thanks. It works

Connectez-vous pour commenter.

### Réponse acceptée

KSSV le 9 Nov 2021
idx = reshape(randperm(12),[],2)
idx = 6×2
2 11 8 10 9 12 7 4 6 1 5 3
##### 0 commentairesAfficher -2 commentaires plus anciensMasquer -2 commentaires plus anciens

Connectez-vous pour commenter.

### Catégories

En savoir plus sur Matrix Indexing dans Help Center et File Exchange

### Community Treasure Hunt

Find the treasures in MATLAB Central and discover how the community can help you!

Start Hunting!

Translated by