Filter löschen
Filter löschen

How to randomise scalars in a vector, in steps of 4?

1 Ansicht (letzte 30 Tage)
Bianca Elena Ivanof
Bianca Elena Ivanof am 18 Dez. 2016
Beantwortet: Star Strider am 19 Dez. 2016
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.

Antworten (2)

Image Analyst
Image Analyst am 18 Dez. 2016
Try randperm() to scramble the positions of the 1-4 numbers for each subcondition.
  1 Kommentar
Bianca Elena Ivanof
Bianca Elena Ivanof am 19 Dez. 2016
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.

Melden Sie sich an, um zu kommentieren.


Star Strider
Star Strider am 19 Dez. 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

Kategorien

Mehr zu Loops and Conditional Statements finden Sie in Help Center und File Exchange

Community Treasure Hunt

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

Start Hunting!

Translated by