|
57 | 57 |
|
58 | 58 | % Set variables here for a dummy test of this function |
59 | 59 | if nargin < 1 || isempty(cfg) |
60 | | - % cfg.design.motionType = 'translation'; |
61 | | - cfg.design.motionType = 'translation'; |
62 | | - cfg.design.names = {'static'; 'motion'}; |
63 | | - cfg.design.nbRepetitions = 16; |
64 | | - cfg.design.nbEventsPerBlock = 12; |
65 | | - cfg.target.maxNbPerBlock = 0; |
66 | | - displayFigs = 1; |
| 60 | + error('give me something to work with'); |
67 | 61 | end |
68 | 62 |
|
69 | 63 | fprintf('\n\nCreating design.\n\n') |
70 | 64 |
|
71 | | - |
72 | 65 | [NB_BLOCKS, NB_REPETITIONS, NB_EVENTS_PER_BLOCK, MAX_TARGET_PER_BLOCK] = getInput(cfg); |
73 | 66 | [~, STATIC_INDEX, MOTION_INDEX] = assignConditions(cfg); |
74 | 67 |
|
75 | | - RANGE_TARGETS = [1 MAX_TARGET_PER_BLOCK]; |
76 | | - targetPerCondition = repmat(RANGE_TARGETS, 1, NB_REPETITIONS / 2); |
| 68 | + RANGE_TARGETS = 1:MAX_TARGET_PER_BLOCK; |
| 69 | + targetPerCondition = repmat(RANGE_TARGETS, 1, NB_REPETITIONS / MAX_TARGET_PER_BLOCK); |
77 | 70 |
|
78 | 71 | numTargetsForEachBlock = zeros(1, NB_BLOCKS); |
79 | 72 | numTargetsForEachBlock(STATIC_INDEX) = shuffle(targetPerCondition); |
|
92 | 85 | % - targets cannot be on the first or last event of a block |
93 | 86 | % - no more than 2 target in the same event order |
94 | 87 |
|
95 | | - chosenTarget = []; |
96 | | - |
97 | | - tmpTarget = numTargetsForEachBlock(iBlock); |
98 | | - |
99 | | - switch tmpTarget |
100 | | - |
101 | | - case 1 |
102 | | - |
103 | | - chosenTarget = randsample(2:NB_EVENTS_PER_BLOCK - 1, tmpTarget, false); |
| 88 | + nbTarget = numTargetsForEachBlock(iBlock); |
104 | 89 |
|
105 | | - case 2 |
| 90 | + chosenPosition = setTargetPositionInSequence( ... |
| 91 | + NB_EVENTS_PER_BLOCK, ... |
| 92 | + nbTarget, ... |
| 93 | + [1 NB_EVENTS_PER_BLOCK]); |
106 | 94 |
|
107 | | - targetDifference = 0; |
108 | | - |
109 | | - while any(targetDifference <= 2) |
110 | | - chosenTarget = randsample(2:NB_EVENTS_PER_BLOCK - 1, tmpTarget, false); |
111 | | - targetDifference = diff(chosenTarget); |
112 | | - end |
113 | | - |
114 | | - end |
115 | | - |
116 | | - fixationTargets(iBlock, chosenTarget) = 1; |
| 95 | + fixationTargets(iBlock, chosenPosition) = 1; |
117 | 96 |
|
118 | 97 | end |
119 | 98 |
|
120 | 99 | % Check rule 3 |
121 | | - if max(sum(fixationTargets)) < 3 |
| 100 | + if max(sum(fixationTargets)) < NB_REPETITIONS - 1 |
122 | 101 | break |
123 | 102 | end |
124 | 103 |
|
|
154 | 133 | directions = zeros(NB_BLOCKS, NB_EVENTS_PER_BLOCK); |
155 | 134 |
|
156 | 135 | % Create a vector for the static condition |
| 136 | + NB_REPEATS_BASE_VECTOR = NB_EVENTS_PER_BLOCK / length(STATIC_DIRECTIONS); |
| 137 | + |
157 | 138 | static_directions = repmat( ... |
158 | 139 | STATIC_DIRECTIONS, ... |
159 | | - 1, NB_EVENTS_PER_BLOCK / length(STATIC_DIRECTIONS)); |
| 140 | + 1, NB_REPEATS_BASE_VECTOR); |
160 | 141 |
|
161 | 142 | for iMotionBlock = 1:NB_REPETITIONS |
162 | 143 |
|
163 | | - % Check that we never have twice the same direction |
164 | | - while 1 |
165 | | - tmp = [ ... |
166 | | - shuffle(MOTION_DIRECTIONS), ... |
167 | | - shuffle(MOTION_DIRECTIONS), ... |
168 | | - shuffle(MOTION_DIRECTIONS)]; |
169 | | - |
170 | | - if ~any(diff(tmp, [], 2) == 0) |
171 | | - break |
172 | | - end |
173 | | - end |
174 | | - |
175 | 144 | % Set motion direction and static order |
176 | | - directions(MOTION_INDEX(iMotionBlock), :) = tmp; |
| 145 | + directions(MOTION_INDEX(iMotionBlock), :) = ... |
| 146 | + repeatShuffleConditions(MOTION_DIRECTIONS, NB_REPEATS_BASE_VECTOR); |
177 | 147 | directions(STATIC_INDEX(iMotionBlock), :) = static_directions; |
178 | 148 |
|
179 | 149 | end |
|
187 | 157 | % CONSTANTS |
188 | 158 | % Set directions for static and motion condition |
189 | 159 |
|
190 | | - STATIC_DIRECTIONS = [-1 -1 -1 -1]; |
191 | | - |
192 | | - switch cfg.design.motionType |
193 | | - case 'translation' |
194 | | - MOTION_DIRECTIONS = [0 0 180 180]; |
195 | | - case 'radial' |
196 | | - STATIC_DIRECTIONS = [666 -666 666 -666]; |
197 | | - MOTION_DIRECTIONS = [666 -666 666 -666]; |
198 | | - end |
| 160 | + MOTION_DIRECTIONS = cfg.design.motionDirections; |
| 161 | + STATIC_DIRECTIONS = repmat(-1, size(MOTION_DIRECTIONS)); |
199 | 162 |
|
200 | 163 | end |
201 | 164 |
|
|
206 | 169 | nbBlocks = length(cfg.design.names) * nbRepet; |
207 | 170 | end |
208 | 171 |
|
209 | | -function [condition, STATIC_INDEX, MOTION_INDEX] = assignConditions(cfg) |
| 172 | +function [conditionNamesVector, STATIC_INDEX, MOTION_INDEX] = assignConditions(cfg) |
210 | 173 |
|
211 | 174 | [~, nbRepet] = getInput(cfg); |
212 | 175 |
|
213 | | - condition = repmat(cfg.design.names, nbRepet, 1); |
| 176 | + conditionNamesVector = repmat(cfg.design.names, nbRepet, 1); |
214 | 177 |
|
215 | 178 | % Get the index of each condition |
216 | | - STATIC_INDEX = find(strcmp(condition, 'static')); |
217 | | - MOTION_INDEX = find(strcmp(condition, 'motion')); |
218 | | - |
219 | | -end |
| 179 | + STATIC_INDEX = find(strcmp(conditionNamesVector, 'static')); |
| 180 | + MOTION_INDEX = find(strcmp(conditionNamesVector, 'motion')); |
220 | 181 |
|
221 | | -function shuffled = shuffle(unshuffled) |
222 | | - % in case PTB is not in the path |
223 | | - try |
224 | | - shuffled = Shuffle(unshuffled); |
225 | | - catch |
226 | | - shuffled = unshuffled(randperm(length(unshuffled))); |
227 | | - end |
228 | 182 | end |
229 | 183 |
|
230 | 184 | function diplayDesign(cfg, displayFigs) |
|
0 commit comments