2016-12-01 15 views
0

Ich habe drei 1x56 Strukturen - Blöcke (Block1, Block2, Block3). Ich muss eine große Struktur (Experiment) erstellen, die alle Blöcke enthält, was kein Problem ist (exp = [Block1 Block2 Block3]). Das Problem besteht darin, die Blöcke innerhalb des Experiments zu mischen, ohne den Inhalt jedes Blocks mit dem Inhalt anderer Blöcke zu mischen.Shuffle Strukturen innerhalb einer Struktur

Zum Beispiel:

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' 

Ich möchte 111333222 oder 333222111 oder 222333111 und so weiter, aber nie 132.123.112 usw.

Ich bedaure es nicht ganz klar ist, ich bin ganz neu in Matlab. Ich würde wirklich Ihre Ideen und Hilfe schätzen!

Antwort

1

Wenn ich richtig verstehe, können Sie es auf diese Weise tun:

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 
0

Die aktuelle Struktur, die Sie verwenden, ziemlich verwirrend ist. Es sieht für mich so aus, als ob Sie wollen block1(1).block die erste Studie in block1 (vorausgesetzt, Sie haben Versuche innerhalb von Blöcken wegen der PsychToolbox-Tag). Ich schlage eine einzelne Struktur vor, die ein Array aller Blöcke enthält. Ebenso enthält jeder Block ein Array aller Versuche innerhalb dieses Blocks. Jeder Versuch enthält die Informationen, die für diese Teilmenge dieses Blocks relevant sind.

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 
Verwandte Themen