|
65 | 65 | fprintf('\n\nCreating design.\n\n'); |
66 | 66 |
|
67 | 67 | [NB_BLOCKS, NB_REPETITIONS, NB_EVENTS_PER_BLOCK, MAX_TARGET_PER_BLOCK] = getDesignInput(cfg); |
68 | | - [~, STATIC_INDEX, MOTION_INDEX] = assignConditions(cfg); |
| 68 | + [~, CONDITON1_INDEX, CONDITON2_INDEX] = assignConditions(cfg); |
69 | 69 |
|
70 | 70 | if mod(NB_REPETITIONS, MAX_TARGET_PER_BLOCK) ~= 0 |
71 | 71 | error('number of repetitions must be a multiple of max number of targets'); |
|
75 | 75 | targetPerCondition = repmat(RANGE_TARGETS, 1, NB_REPETITIONS / MAX_TARGET_PER_BLOCK); |
76 | 76 |
|
77 | 77 | numTargetsForEachBlock = zeros(1, NB_BLOCKS); |
78 | | - numTargetsForEachBlock(STATIC_INDEX) = shuffle(targetPerCondition); |
79 | | - numTargetsForEachBlock(MOTION_INDEX) = shuffle(targetPerCondition); |
| 78 | + numTargetsForEachBlock(CONDITON1_INDEX) = shuffle(targetPerCondition); |
| 79 | + numTargetsForEachBlock(CONDITON2_INDEX) = shuffle(targetPerCondition); |
80 | 80 |
|
81 | 81 | %% Give the blocks the names with condition and design the task in each event |
82 | 82 | while 1 |
|
125 | 125 | diplayDesign(cfg, displayFigs); |
126 | 126 |
|
127 | 127 | end |
128 | | - |
129 | | -function cfg = setDirections(cfg) |
130 | | - |
131 | | - [MOTION_DIRECTIONS, STATIC_DIRECTIONS] = getDirectionBaseVectors(cfg); |
132 | | - |
133 | | - [NB_BLOCKS, NB_REPETITIONS, NB_EVENTS_PER_BLOCK] = getDesignInput(cfg); |
134 | | - |
135 | | - [~, STATIC_INDEX, MOTION_INDEX] = assignConditions(cfg); |
136 | | - |
137 | | - if mod(NB_EVENTS_PER_BLOCK, length(MOTION_DIRECTIONS)) ~= 0 |
138 | | - error('Number of events/block not a multiple of number of motion/static direction'); |
139 | | - end |
140 | | - |
141 | | - % initialize |
142 | | - directions = zeros(NB_BLOCKS, NB_EVENTS_PER_BLOCK); |
143 | | - |
144 | | - % Create a vector for the static condition |
145 | | - NB_REPEATS_BASE_VECTOR = NB_EVENTS_PER_BLOCK / length(STATIC_DIRECTIONS); |
146 | | - |
147 | | - static_directions = repmat( ... |
148 | | - STATIC_DIRECTIONS, ... |
149 | | - 1, NB_REPEATS_BASE_VECTOR); |
150 | | - |
151 | | - for iMotionBlock = 1:NB_REPETITIONS |
152 | | - |
153 | | - % Set motion direction and static order |
154 | | - directions(MOTION_INDEX(iMotionBlock), :) = ... |
155 | | - repeatShuffleConditions(MOTION_DIRECTIONS, NB_REPEATS_BASE_VECTOR); |
156 | | - directions(STATIC_INDEX(iMotionBlock), :) = static_directions; |
157 | | - |
158 | | - end |
159 | | - |
160 | | - cfg.design.directions = directions; |
161 | | - |
162 | | -end |
163 | | - |
164 | | -function [MOTION_DIRECTIONS, STATIC_DIRECTIONS] = getDirectionBaseVectors(cfg) |
165 | | - |
166 | | - % CONSTANTS |
167 | | - % Set directions for static and motion condition |
168 | | - |
169 | | - MOTION_DIRECTIONS = cfg.design.motionDirections; |
170 | | - STATIC_DIRECTIONS = repmat(-1, size(MOTION_DIRECTIONS)); |
171 | | - |
172 | | -end |
173 | | - |
174 | | -function [conditionNamesVector, STATIC_INDEX, MOTION_INDEX] = assignConditions(cfg) |
175 | | - |
176 | | - [~, nbRepet] = getDesignInput(cfg); |
177 | | - |
178 | | - conditionNamesVector = repmat(cfg.design.names, nbRepet, 1); |
179 | | - |
180 | | - % Get the index of each condition |
181 | | - STATIC_INDEX = find(strcmp(conditionNamesVector, 'static')); |
182 | | - MOTION_INDEX = find(strcmp(conditionNamesVector, 'motion')); |
183 | | - |
184 | | -end |
185 | | - |
186 | | -function diplayDesign(cfg, displayFigs) |
187 | | - |
188 | | - %% Visualize the design matrix |
189 | | - if displayFigs |
190 | | - |
191 | | - close all; |
192 | | - |
193 | | - figure(1); |
194 | | - |
195 | | - % Shows blocks (static and motion) and events (motion direction) order |
196 | | - directions = cfg.design.directions; |
197 | | - directions(directions == -1) = -90; |
198 | | - |
199 | | - subplot(3, 1, 1); |
200 | | - imagesc(directions); |
201 | | - |
202 | | - labelAxesBlock(); |
203 | | - |
204 | | - caxis([-90 - 37, 270 + 37]); |
205 | | - myColorMap = lines(5); |
206 | | - colormap(myColorMap); |
207 | | - |
208 | | - title('Block (static and motion) & Events (motion direction)'); |
209 | | - |
210 | | - % Shows the fixation targets design in each event (1 or 0) |
211 | | - fixationTargets = cfg.design.fixationTargets; |
212 | | - |
213 | | - subplot(3, 1, 2); |
214 | | - imagesc(fixationTargets); |
215 | | - labelAxesBlock(); |
216 | | - title('Fixation Targets design'); |
217 | | - colormap(gray); |
218 | | - |
219 | | - % Shows the fixation targets position distribution in the block across |
220 | | - % the experimet |
221 | | - [~, itargetPosition] = find(fixationTargets == 1); |
222 | | - |
223 | | - subplot(3, 1, 3); |
224 | | - hist(itargetPosition); |
225 | | - labelAxesFreq(); |
226 | | - title('Fixation Targets position distribution'); |
227 | | - |
228 | | - figure(2); |
229 | | - |
230 | | - [motionDirections] = getDirectionBaseVectors(cfg); |
231 | | - motionDirections = unique(motionDirections); |
232 | | - |
233 | | - for iMotion = 1:length(motionDirections) |
234 | | - |
235 | | - [~, position] = find(directions == motionDirections(iMotion)); |
236 | | - |
237 | | - subplot(2, 2, iMotion); |
238 | | - hist(position); |
239 | | - scaleAxes(); |
240 | | - labelAxesFreq(); |
241 | | - title(num2str(motionDirections(iMotion))); |
242 | | - |
243 | | - end |
244 | | - |
245 | | - end |
246 | | - |
247 | | -end |
248 | | - |
249 | | -function labelAxesBlock() |
250 | | - % an old viking saying because they really cared about their axes |
251 | | - ylabel('Block seq.', 'Fontsize', 8); |
252 | | - xlabel('Events', 'Fontsize', 8); |
253 | | -end |
254 | | - |
255 | | -function labelAxesFreq() |
256 | | - % an old viking saying because they really cared about their axes |
257 | | - ylabel('Number of targets', 'Fontsize', 8); |
258 | | - xlabel('Events', 'Fontsize', 8); |
259 | | -end |
260 | | - |
261 | | -function scaleAxes() |
262 | | - xlim([1 12]); |
263 | | - ylim([0 5]); |
264 | | -end |
0 commit comments