Skip to content

Commit a8bc6b5

Browse files
committed
fix issue with static dots
fix issue static dots
1 parent c087f43 commit a8bc6b5

File tree

2 files changed

+19
-8
lines changed

2 files changed

+19
-8
lines changed

initializeDots.m renamed to initDots.m

Lines changed: 11 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
function [dots] = initializeDots(cfg, thisEvent)
1+
function [dots] = initDots(cfg, thisEvent)
22

33
direction = thisEvent.direction(1);
44

@@ -12,8 +12,8 @@
1212
% for static dots
1313
if direction == -1
1414
speedPixPerFrame = 0;
15-
dots.lifeTime = cfg.eventDuration;
16-
dots.isSignal = ones(cfg.dot.number, 1);
15+
dots.lifeTime = Inf;
16+
dots.isSignal = true(cfg.dot.number, 1);
1717
end
1818

1919
% Convert from seconds to frames
@@ -33,17 +33,20 @@
3333
dots.speeds(dots.isSignal, :) = ...
3434
repmat([horVector, vertVector], sum(dots.isSignal), 1);
3535

36-
% If not 100% coherence, we get new random direction for the other dots
37-
direction = rand(sum(~dots.isSignal), 1) * 360;
38-
[horVector, vertVector] = decompMotion(direction);
39-
dots.speeds(~dots.isSignal, :) = [horVector, vertVector];
36+
% Random direction for the non coherent dots
37+
if any(~dots.isSignal)
38+
randomDirection = rand(sum(~dots.isSignal), 1) * 360;
39+
[horVector, vertVector] = decompMotion(randomDirection);
40+
dots.speeds(~dots.isSignal, :) = [horVector, vertVector];
41+
end
4042

4143
% So far we were working wiht unit vectors convert that speed in pixels per
4244
% frame
4345
dots.speeds = dots.speeds * speedPixPerFrame;
4446

4547
% Create a vector to update to dotlife time of each dot
46-
% Not all set to one so the dots will die at different times
48+
% Not all set to 1 so the dots will die at different times
49+
% The maximum value is the duraion of the event in frames
4750
dots.time = floor(rand(cfg.dot.number, 1) * cfg.eventDuration / cfg.screen.ifi);
4851

4952
end

updateDots.m

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -3,6 +3,13 @@
33
% Move the selected dots
44
dots.positions = dots.positions + dots.speeds;
55

6+
if all(isnan(dots.positions(:)))
7+
errorStruct.message = 'All dots position have NaN values.';
8+
errorStruct.identifier = 'updateDots:onlyNans';
9+
10+
error(errorStruct);
11+
end
12+
613
% Create a logical vector to detect any dot that has:
714
% - an xy position inferior to 0
815
% - an xy position superior to winWidth
@@ -23,4 +30,5 @@
2330

2431
% Add one frame to the dot lifetime to each dot
2532
dots.time = dots.time + 1;
33+
2634
end

0 commit comments

Comments
 (0)