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

A=[1:12]
now I want to pair two numbers randomly in each pair as [ 1 3] [ 2 6] [7 9] .....
Could anyobe please help me on this.

댓글 수: 4

HI jaah,
try randperm(12), that should give you some ideas.
I tried
randperm(12)
and got the result as
12 9 3 11 4 1 5 8 10 7 2 6
but i want to have the numbers in pairs [ 12 9 ] [ 3 11],... such that numbers should not be repeated again.
Could you help me on this.
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
Thanks. It works

댓글을 달려면 로그인하십시오.

 채택된 답변

idx = reshape(randperm(12),[],2)
idx = 6×2
2 11 8 10 9 12 7 4 6 1 5 3

추가 답변 (0개)

카테고리

도움말 센터File Exchange에서 Creating and Concatenating Matrices에 대해 자세히 알아보기

태그

질문:

2021년 11월 9일

댓글:

2021년 11월 9일

Community Treasure Hunt

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

Start Hunting!

Translated by