How to randomise scalars in a vector, in steps of 4?
1 visualización (últimos 30 días)
Mostrar comentarios más antiguos
Dear all,
I am trying to randomise the subconditions of the main conditions of my experiment (please see counterbalancing.mat attached). Column 2 of counterbalancing.mat contains speed levels (1, 2, 3) and column 3 sub-conditions (1, 2, 3, 4) for each speed level in column 3. What I am trying to do is, for every speed level (column 2), to randomise the 4 sub-conditions (column 3) - i.e. to randomise in steps of 4 - the first 4 rows containing 1, 2, 3, 4 and then the next 4 rows containing 1, 2, 3, 4 and so on and so forth, so that each and every speed level in column 2 has a different combination of 1, 2, 3 and 4's in column 3, if that makes sense.
I've tried using counterbalancing(1:4:408,3) but then it's dawned on me that this gives me a bunch of 1's because every row which is a multiple of 4 contains 1.......... I've then tried a for loop, but haven't been successful.
Could you please be so kind as to help me? Thank you very much in advance.
0 comentarios
Respuestas (2)
Image Analyst
el 18 de Dic. de 2016
Try randperm() to scramble the positions of the 1-4 numbers for each subcondition.
1 comentario
Star Strider
el 19 de Dic. de 2016
See if the perms function will do what you want:
Q = perms(1:4)
Q =
4 3 2 1
4 3 1 2
4 2 3 1
4 2 1 3
4 1 3 2
4 1 2 3
3 4 2 1
3 4 1 2
3 2 4 1
3 2 1 4
3 1 4 2
3 1 2 4
2 4 3 1
2 4 1 3
2 3 4 1
2 3 1 4
2 1 4 3
2 1 3 4
1 4 3 2
1 4 2 3
1 3 4 2
1 3 2 4
1 2 4 3
1 2 3 4
0 comentarios
Ver también
Categorías
Más información sobre Loops and Conditional Statements en Help Center y File Exchange.
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!