How to randomise scalars in a vector, in steps of 4?
1 次查看(过去 30 天)
显示 更早的评论
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 个评论
回答(2 个)
Image Analyst
2016-12-18
Try randperm() to scramble the positions of the 1-4 numbers for each subcondition.
Star Strider
2016-12-19
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 个评论
另请参阅
类别
在 Help Center 和 File Exchange 中查找有关 Loops and Conditional Statements 的更多信息
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!