-
Notifications
You must be signed in to change notification settings - Fork 3
/
Copy pathindicate_strokes.m
119 lines (110 loc) · 3.72 KB
/
indicate_strokes.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
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
function indicate_strokes(varargin)
%% function indicate_strokes(varargin)
% add shaded areas in the background of existing plots, usually to
% highlight up/downstrokes.
% -------------------------------------------------------------------------
% Inputs:
% none
% Optional:
% 'figure' followed by an integer: number of figure to use. default: gcf
% 'color' followed by vector: color of shaed areas
% 'frame' yes/no: put frames around shaded areas
% 't_begin' array of times beginning of downstroke
% 't_reversal' array of times of stroke reversals
% If t_begin and t_reversal are missing, unit period time and symmetric up/
% downstroke are assumed
% -------------------------------------------------------------------------
% Output:
% none
% -------------------------------------------------------------------------
%% define default values here:
fig = gcf;
color = [0.85 0.85 0.85];
frame = 'no';
t_begin = 0;
t_reversal = 0;
%% read in optional arguments
i = 1;
while i <= length(varargin)
switch varargin{i}
case 'figure'
% check if we're not at the end of the parameter list
assert(i+1<=numel(varargin),'missing an argument!');
i = i+1;
% check if next argument is numeric
if (~isnumeric(varargin{i}))
error(['Parameter value for ' varargin{i-1} ' must be numeric!']);
end
% take that value
fig = varargin{i};
case 'color'
% check if we're not at the end of the parameter list
assert(i+1<=numel(varargin),'missing an argument!');
i = i+1;
% check if next argument is numeric
if (~isnumeric(varargin{i}))
error(['Parameter value for ' varargin{i-1} ' must be numeric!']);
end
color = varargin{i};
case 'frame'
assert(i+1<=numel(varargin),'missing an argument!');
i = i+1;
if (~ischar(varargin{i}))
error(['Parameter value for ' varargin{i-1} ' must be string!']);
end
frame = varargin{i};
case 't_begin'
assert(i+1<=numel(varargin),'missing an argument!');
i = i+1;
if (~isnumeric(varargin{i}))
error(['Parameter value for ' varargin{i-1} ' must be numeric!']);
end
t_begin = varargin{i};
case 't_reversal'
assert(i+1<=numel(varargin),'missing an argument!');
i = i+1;
if (~isnumeric(varargin{i}))
error(['Parameter value for ' varargin{i-1} ' must be numeric!']);
end
t_reversal = varargin{i};
otherwise
error(['unkown parameter:' varargin{i}])
end
i=i+1;
end
% determine what the current axis are
figure(fig)
a = axis;
tmin = a(1);
tmax = a(2);
fmin = a(3);
fmax = a(4);
% determine beginnings of shaded areas (beginning of downstroke)
if (length(t_begin)>1)
tdown = t_begin;
else
if (tmin > 0.0)
warning('Start time of figure is not zero, we dont start at integer strokes. Consider passing t_begin array');
end
tdown = tmin:tmax-1;
end
% determine end of shaded areas (reversal timing)
if (length(t_reversal)>1)
treversal = t_reversal;
else
treversal = tdown + 0.5;
end
for i = 1:length(tdown)
if (strcmp(frame,'yes'))
patch( [tdown(i) treversal(i) treversal(i) tdown(i)], [fmin fmin fmax fmax],...
[-1 -1 -1 -1], color);
else
patch( [tdown(i) treversal(i) treversal(i) tdown(i)], [fmin fmin fmax fmax],...
[-1 -1 -1 -1], color,'LineStyle','none');
end
end
% outer frame
if (strcmp(frame,'yes'))
patch( [tmin tmax tmax tmin], [fmin fmin fmax fmax], [-2 -2 -2 -2],[1 1 1]);
end
set(gca,'Layer','top')