-
Notifications
You must be signed in to change notification settings - Fork 1
/
Copy pathplotlatency.m
231 lines (209 loc) · 7.96 KB
/
plotlatency.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
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
function [L,eh] = plotlatency(DATA,groups,varargin)
% function [L, H] = plotlatency(DATA,GROUPS,varargin)
%
% Plots the escape latencies from the given data using the given indices of different groups.
%
% MANDATORY INPUTS:
% -------------------------------------------------------------------------------------------------
%
% DATA - DATA is a cell array that contains the raw water-maze data for a given collection of
% project files in the study. See 'help readwmdf' for details.
%
% GROUPS - A cell array of vectors of animal indices. See 'help getgroups' to determine how to
% build these vectors.
%
% OUTPUT:
% -------------------------------------------------------------------------------------------------
%
% L - A T x A matrix of latencies, where T is the maximum number of trials and A is the number of
% animals.
%
% H - A cell array of handles for the plot.
%
% OPTIONAL INPUTS:
% -------------------------------------------------------------------------------------------------
% Optional inputs to control plotting behaviour can be provided in parameter/value format. The optional inputs are:
%
% 'days' - A cell array of vectors of trial indices to indicate which trials were on different
% days. Trials on different days are not joined by a line (i.e. a gap appears in the
% plot). Default = {} (all trials on the same day).
%
% 'line_width' - A scalar value determing the line widths of the plot. Default = 1.
%
% 'marker_size' - A scalar value determing the size of the symbols on the plot. Default = 5.
%
% 'font_size' - A scalar value determing the size of the font used in the axis. Default = 12.
%
% 'font_name' - A string defining which font is used in the axis. Default = lucidasans.
%
% 'grp_edgec' - A cell array determining the colours of the lines for each group. Default =
% {'b','r','g','k','m','c','y'}.
%
% 'grp_facec' - A cell array determining the colours of the symbols for each group. Default =
% {'b','r','g','k','m','c','y'}.
%
% 'grp_symbol' - A cell array determining the symbols for each group. Default = {'o','s','^',
% '+','x','d','p'}.
%
% 'grp_style' - A cell array determining the line styles for each group. Default = {'-',':','-.','--'}.
%
% 'tick_dir' - Whether ticks should be 'in' or 'out. Default = 'out'.
%
%--------------------------------------------------------------------------------
%
% 02/2013, Frankland Lab (www.franklandlab.com)
%
% Author: Blake Richards
% Contact: [email protected]
%
%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
% Copyright 2013 Blake Richards ([email protected])
%
% This file is part of the MWM Matlab Toolbox.
%
% The MWM Toolbox is free software: you can redistribute it and/or modify
% it under the terms of the GNU Lesser General Public License as published by
% the Free Software Foundation, either version 3 of the License, or
% (at your option) any later version.
%
% The MWM Toolbox is distributed in the hope that it will be useful,
% but WITHOUT ANY WARRANTY; without even the implied warranty of
% MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
% GNU Lesser General Public License for more details.
%
% You should have received a copy of the GNU Lesser General Public License
% along with the MWM Toolbox (in the file COPYING.LESSER). If not,
% see <http://www.gnu.org/licenses/>.
%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
% PARSE THE INPUT
% define the default optional arguments
optargs = struct('days',[],...
'line_width',1,...
'marker_size',5,...
'font_size',12,...
'font_name','lucidasans',...
'grp_edgec',{{'b','r','g','k','m','c','y'}},...
'grp_facec',{{'b','r','g','k','m','c','y'}},...
'grp_symbol',{{'o','s','^','+','x','d','p'}},...
'grp_style',{{'-',':','-.','--'}},...
'tick_dir','out');
% get the optional argument names
optnames = fieldnames(optargs);
% get the number of optional arguments
nargs = length(varargin)/2;
% make sure the property/value pairs are input in pairs
if round(length(varargin)/2) ~= nargs
error('Expecting propertyName/propertyValue pairs after DATA and GROUPS');
end
% step through the optional arguments, check them, and store them
for pair = reshape(varargin,2,[])
% make it case insensitive
inpname = lower(pair{1});
% check whether the name matches a known option
if any(strmatch(inpname,optnames))
switch inpname
case 'days'
if isa(pair{2},'cell')
optargs.(inpname) = pair{2};
else
error('days must be a cell array');
end
case 'line_width'
if isa(pair{2},'numeric')
optargs.(inpname) = pair{2};
else
error('line_width must be a scalar value');
end
case 'marker_size'
if isa(pair{2},'numeric')
optargs.(inpname) = pair{2};
else
error('marker_size must be a scalar value');
end
case 'font_size'
if isa(pair{2},'numeric')
optargs.(inpname) = pair{2};
else
error('font_size must be a scalar value');
end
case 'font_name'
if isa(pair{2},'char') && ismember(pair{2},listfonts())
optargs.(inpname) = pair{2};
else
error('font_name must be a valid font name (see help listfonts)');
end
case 'grp_edgec'
if isa(pair{2},'cell')
optargs.(inpname) = pair{2};
else
error('grp_edgec must be a cell array');
end
case 'grp_facec'
if isa(pair{2},'cell')
optargs.(inpname) = pair{2};
else
error('grp_facec must be a cell array');
end
case 'grp_symbol'
if isa(pair{2},'cell')
optargs.(inpname) = pair{2};
else
error('grp_symbol must be a cell array');
end
case 'grp_style'
if isa(pair{2},'cell')
optargs.(inpname) = pair{2};
else
error('grp_style must be a cell array');
end
case 'tick_dir'
if isa(pair{2},'char') && ismember(pair{2},{'in','out'})
optargs.(inpname) = pair{2};
else
error('tick_dir must be ''in'' or ''out''');
end
end
else
error('%s is not a recognized parameter name',inpname);
end
end
%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
% PLOT THE DATA
% get the latencies
L = getlatency(DATA);
% make the figure
figure();
set(gcf,'Color',[1 1 1],'Position',[300 200 800 400],'PaperPosition',[0 0 8 4]);
axes('Position',[0.1 0.2 0.8 0.7]);
hold on;
% for each day...
if isempty(optargs.days), days = {[1:size(L,1)]}; else, days = optargs.days; end;
for dd = 1:length(days)
% get the xdata for these trials
xdata = dd + linspace(0.2,0.8,length(days{dd}));
% plot the data for each group on this day
for gg = 1:length(groups)
% calculate the y-values
ymean = mean(L(days{dd},groups{gg}),2);
ysem = std(L(days{dd},groups{gg}),[],2)./sqrt(length(groups{gg}));
% plot the errorbars and format
eh{gg} = errorbar(xdata,ymean,ysem);
set(eh{gg},'MarkerFaceColor',optargs.grp_facec{mod(gg-1,length(optargs.grp_facec))+1},...
'MarkerEdgeColor',optargs.grp_edgec{mod(gg-1,length(optargs.grp_edgec))+1},...
'Color',optargs.grp_edgec{mod(gg-1,length(optargs.grp_edgec))+1},...
'Marker',optargs.grp_symbol{mod(gg-1,length(optargs.grp_symbol))+1},...
'LineStyle',optargs.grp_style{mod(gg-1,length(optargs.grp_style))+1},...
'MarkerSize',optargs.marker_size,...
'LineWidth',optargs.line_width);
end
end
% Add labels and tick marks
xlabel('Day','FontName',optargs.font_name,'FontSize',optargs.font_size);
ylabel('Escape latency (s)','FontName',optargs.font_name,'FontSize',optargs.font_size);
set(gca,'XTick',[1:length(days)]+0.5,'XTickLabel',[1:length(days)]);
set(gca,'YTick',[0:10:60],'YTickLabel',[0:10:60]);
% beautify the figure
axis([1 length(days)+1 0 65]);
set(gca,'TickDir',optargs.tick_dir,'LineWidth',optargs.line_width);
set(gca,'FontName',optargs.font_name,'FontSize',optargs.font_size);