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.

回答(2 个)

Image Analyst
Image Analyst 2016-12-18
Try randperm() to scramble the positions of the 1-4 numbers for each subcondition.
  1 个评论
Bianca Elena Ivanof
Bianca Elena Ivanof 2016-12-19
Hello,
Thank you for your response. I know randperm, I've tried it like this
scramble_subcond= counterbalancing(:,3);
counterbalancing(:,3)= scramble_subcond(randperm(numel(scramble_subcond)));
This does randomise it but it doesn't solve my issue - i.e. there will be speed levels in column 2 that only have subconditions 2, 2, 3, 3 in column 3, for example, whereas what I need is different combinations of all 1, 2, 3, and 4's per speed level.

请先登录,再进行评论。


Star Strider
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

类别

Help CenterFile Exchange 中查找有关 Loops and Conditional Statements 的更多信息

Community Treasure Hunt

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

Start Hunting!

Translated by