arrays - Pairs of random numbers Matlab -
i trying generate random numbers between 1 , 6 using matlab's randperm
, calling randperm = 6
.
each time gives me different array let's example:
x = randperm(6) x = [3 2 4 1 5 6]
i wondering if possible create pairs of random numbers such end x
like:
x = [3 4 1 2 5 6]
i need vector arranged such 1 , 2 next each other, 3 , 4 next each other , 5 , 6 next each other. i'm doing in psychtoolbox
, order important.
is possible have "blocks" of random order? can't figure out how it.
thanks
i can see simple 3 step process desired output:
- produce
2*randperm(3)
- double values
- add
randperm(2)-2
(randomly ordered pair of(-1,0)
) each pair.
in code:
x = randperm(3) y = 2*x([1 1 2 2 3 3]) z = y + ([randperm(2),randperm(2),randperm(2)]-2)
with result
x = 3 1 2 y = 6 6 2 2 4 4 z = 6 5 2 1 3 4
Comments
Post a Comment