-
Notifications
You must be signed in to change notification settings - Fork 1
/
Copy pathsparsifyStimulusStruct.m
38 lines (29 loc) · 1.06 KB
/
sparsifyStimulusStruct.m
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
function stimulus = sparsifyStimulusStruct(stimulus, maxUpdateInterval)
numImagesIn = length(stimulus.seq);
keepFrames = true(1,numImagesIn);
mostRecentFrame = 1;
if ~isfield(stimulus, 'trigSeq')
stimulus.trigSeq = zeros(size(stimulus.seq));
removeTrigSeq = true;
else
removeTrigSeq = false;
end
for ii = 2:numImagesIn - 1
thisInterval = stimulus.seqtiming(ii) - stimulus.seqtiming(mostRecentFrame);
didAnyThingChange = any([...
stimulus.seq(ii) ~= stimulus.seq(mostRecentFrame) ...
stimulus.fixSeq(ii) ~= stimulus.fixSeq(mostRecentFrame) ...
stimulus.trigSeq(ii) ~= stimulus.trigSeq(mostRecentFrame) ...
]);
if thisInterval < maxUpdateInterval && ~didAnyThingChange
keepFrames(ii) = false;
else
mostRecentFrame = ii;
end
end
stimulus.seqtiming = stimulus.seqtiming(keepFrames);
stimulus.seq = stimulus.seq(keepFrames);
stimulus.fixSeq = stimulus.fixSeq(keepFrames);
stimulus.trigSeq = stimulus.trigSeq(keepFrames);
if removeTrigSeq, stimulus = rmfield(stimulus, 'trigSeq'); end
end