Skip to content

Commit d91b235

Browse files
committed
refactor expDesign
1 parent 1fe86ef commit d91b235

File tree

6 files changed

+173
-314
lines changed

6 files changed

+173
-314
lines changed

subfun/assignConditions.m

Lines changed: 20 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,20 @@
1+
% (C) Copyright 2020 CPP visual motion localizer developpers
2+
3+
function [conditionNamesVector, CONDITON1_INDEX, CONDITON2_INDEX] = assignConditions(cfg)
4+
5+
[~, nbRepet] = getDesignInput(cfg);
6+
7+
conditionNamesVector = repmat(cfg.design.names, nbRepet, 1);
8+
9+
% Get the index of each condition
10+
nameCondition1 = 'static';
11+
nameCondition2 = 'motion';
12+
if isfield(cfg.design, 'localizer') && strcmpi(cfg.design.localizer, 'MT_MST')
13+
nameCondition1 = 'fixation_right';
14+
nameCondition2 = 'fixation_left';
15+
end
16+
17+
CONDITON1_INDEX = find(strcmp(conditionNamesVector, nameCondition1));
18+
CONDITON2_INDEX = find(strcmp(conditionNamesVector, nameCondition2));
19+
20+
end

subfun/diplayDesign.m

Lines changed: 81 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,81 @@
1+
% (C) Copyright 2020 CPP visual motion localizer developpers
2+
3+
function diplayDesign(cfg, displayFigs)
4+
5+
%% Visualize the design matrix
6+
if displayFigs
7+
8+
close all;
9+
10+
figure(1);
11+
12+
% Shows blocks (static and motion) and events (motion direction) order
13+
directions = cfg.design.directions;
14+
directions(directions == -1) = -90;
15+
16+
subplot(3, 1, 1);
17+
imagesc(directions);
18+
19+
labelAxesBlock();
20+
21+
caxis([-90 - 37, 270 + 37]);
22+
myColorMap = lines(5);
23+
colormap(myColorMap);
24+
25+
title('Block (static and motion) & Events (motion direction)');
26+
27+
% Shows the fixation targets design in each event (1 or 0)
28+
fixationTargets = cfg.design.fixationTargets;
29+
30+
subplot(3, 1, 2);
31+
imagesc(fixationTargets);
32+
labelAxesBlock();
33+
title('Fixation Targets design');
34+
colormap(gray);
35+
36+
% Shows the fixation targets position distribution in the block across
37+
% the experimet
38+
[~, itargetPosition] = find(fixationTargets == 1);
39+
40+
subplot(3, 1, 3);
41+
hist(itargetPosition);
42+
labelAxesFreq();
43+
title('Fixation Targets position distribution');
44+
45+
figure(2);
46+
47+
[motionDirections] = getDirectionBaseVectors(cfg);
48+
motionDirections = unique(motionDirections);
49+
50+
for iMotion = 1:length(motionDirections)
51+
52+
[~, position] = find(directions == motionDirections(iMotion));
53+
54+
subplot(2, 2, iMotion);
55+
hist(position);
56+
scaleAxes();
57+
labelAxesFreq();
58+
title(num2str(motionDirections(iMotion)));
59+
60+
end
61+
62+
end
63+
64+
end
65+
66+
function labelAxesBlock()
67+
% an old viking saying because they really cared about their axes
68+
ylabel('Block seq.', 'Fontsize', 8);
69+
xlabel('Events', 'Fontsize', 8);
70+
end
71+
72+
function labelAxesFreq()
73+
% an old viking saying because they really cared about their axes
74+
ylabel('Number of targets', 'Fontsize', 8);
75+
xlabel('Events', 'Fontsize', 8);
76+
end
77+
78+
function scaleAxes()
79+
xlim([1 12]);
80+
ylim([0 5]);
81+
end

subfun/expDesign.m

Lines changed: 3 additions & 140 deletions
Original file line numberDiff line numberDiff line change
@@ -65,7 +65,7 @@
6565
fprintf('\n\nCreating design.\n\n');
6666

6767
[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);
6969

7070
if mod(NB_REPETITIONS, MAX_TARGET_PER_BLOCK) ~= 0
7171
error('number of repetitions must be a multiple of max number of targets');
@@ -75,8 +75,8 @@
7575
targetPerCondition = repmat(RANGE_TARGETS, 1, NB_REPETITIONS / MAX_TARGET_PER_BLOCK);
7676

7777
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);
8080

8181
%% Give the blocks the names with condition and design the task in each event
8282
while 1
@@ -125,140 +125,3 @@
125125
diplayDesign(cfg, displayFigs);
126126

127127
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

Comments
 (0)