0

I have three 1x56 structures - blocks (block1, block 2, block3). I need to create one big structure (experiment), which includes all the blocks, which is not a problem (exp = [block1 block2 block3]). The problem is how to shuffle the blocks within the experiment, without mixing the content of each block with other blocks' content.

For example:

block1(1).block = '1'     
block1(2).block = '1'    
block1(3).block = '1'    

block2(1).block = '2'    
block2(2).block = '2'    
block2(3).block = '2'    

block3(1).block = '3'   
block3(2).block = '3'   
block3(3).block = '3'   

I want 111333222 or 333222111 or 222333111 and so on, but never 132123112 etc.

I am sorry it's not very clear, I'm quite new to MatLab. I'd really appreciate your ideas and help!

malalota
  • 21
  • 4

2 Answers2

1

If I understand correctly, you can do it this way:

blocks = {block1 block2 block3}; % Collect all blocks in cell array
ind = randperm(numel(blocks)); % Index of random permutation
shuffled_blocks = [blocks{ind}]; % Apply permutation and merge into one struct array 
Luis Mendo
  • 110,752
  • 13
  • 76
  • 147
0

The current structure you are using is quite confusing. It looks to me like you want block1(1).block to represent the first trial in block1 (assuming you have trials within blocks because of the PsychToolbox tag). I propose a single structure containing an array of all blocks. Likewise, each block holds an array of all trials within that block. Each trial holds the information pertinent to that subset of that block.

blocks(1).trials{1} = '1';
blocks(1).trials{2} = '1';
blocks(1).trials{3} = '1';

blocks(2).trials{1} = '2';
blocks(2).trials{2} = '2';
blocks(2).trials{3} = '2';

blocks(3).trials{1} = '3';
blocks(3).trials{2} = '3';
blocks(3).trials{3} = '3';

for blk_ind = randperm(numel(blocks))
    trials = block(blk_ind);
    % when blk_ind == 1, trials is {'1','1','1'}
end
Brendan Frick
  • 1,047
  • 6
  • 19