필터 지우기
필터 지우기

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

조회 수: 1 (최근 30일)
Bianca Elena Ivanof
Bianca Elena Ivanof 2016년 12월 18일
답변: Star Strider 2016년 12월 19일
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