-
Notifications
You must be signed in to change notification settings - Fork 0
/
AnalysisSection.m
176 lines (135 loc) · 5.44 KB
/
AnalysisSection.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
% [x, y] = AnalysisSection(obj, action, x, y)
%
% For doing online analysis of behavior.
%
%
% PARAMETERS:
% -----------
%
% obj Default object argument.
%
% action One of:
% 'init' To initialise the section and set up the GUI
% for it;
%
% 'reinit' Delete all of this section's GUIs and data,
% and reinit, at the same position on the same
% figure as the original section GUI was placed.
%
% Several other actions are available (see code of this file).
%
% x, y Relevant to action = 'init'; they indicate the initial
% position to place the GUI at, in the current figure window
%
% RETURNS:
% --------
%
% [x, y] When action == 'init', returns x and y, pixel positions on
% the current figure, updated after placing of this section's GUI.
%
% x When action = 'get_next_side', x will be either 'l' for
% left or 'r' for right.
%
function [x, y] = AnalysisSection(obj, action, x, y)
GetSoloFunctionArgs;
switch action
case 'init', % ------------ CASE INIT ----------------
% Save the figure and the position in the figure where we are
% going to start adding GUI elements:
SoloParamHandle(obj, 'my_gui_info', 'value', [x y gcf]); next_row(y,1.5);
MenuParam(obj, 'analysis_show', {'view', 'hide'}, 'hide', x, y, 'label', 'Analysis', 'TooltipString', 'Online behavior analysis');
set_callback(analysis_show, {mfilename,'hide_show'});
next_row(y);
SubheaderParam(obj, 'sectiontitle', 'Analysis', x, y);
parentfig_x = x; parentfig_y = y;
% --- Make new window for online analysis
SoloParamHandle(obj, 'analysisfig', 'saveable', 0);
analysisfig.value = figure('Position', [1000 500 400 200], 'Menubar', 'none',...
'Toolbar', 'none','Name','Analysis','NumberTitle','off');
x = 1; y = 1;
DispParam(obj, 'NumTrials', 0, x, y); next_row(y);
DispParam(obj, 'NumRewards', 0, x, y); next_row(y);
DispParam(obj, 'PercentCorrect', 0, x, y); next_row(y);
DispParam(obj, 'HR', 0, x, y); next_row(y);
DispParam(obj, 'FAR', 0, x, y); next_row(y);
DispParam(obj, 'HRMinusFAR', 0, x, y); next_row(y);
DispParam(obj, 'Dprime', 0, x, y); next_row(y);
DispParam(obj, 'Dprime60', 0, x, y); next_row(y);
AnalysisSection(obj,'hide_show');
x = parentfig_x; y = parentfig_y;
set(0,'CurrentFigure',value(myfig));
return;
case 'update'
correct = hit_history;
s1 = (previous_sides(1:(end-1)) == 114)'; % 114 charcode for 'r', 108 for 'l'
trials = [s1 correct];
%---------------------------------------------------
fa = find(trials(:,1)==0 & trials(:,2)==0);
hit = find(trials(:,1)==1 & trials(:,2)==1);
miss = find(trials(:,1)==1 & trials(:,2)==0);
cr = find(trials(:,1)==0 & trials(:,2)==1);
num_s1 = length(hit) + length(miss);
num_s0 = length(fa) + length(cr);
ntrials = num_s1 + num_s0;
if isempty(fa)
far = 0;
else
far = length(fa)/num_s0;
end
if isempty(hit)
hr = 0;
else
hr = length(hit)/num_s1;
end
dp = dprime(hr, far, num_s1, num_s0);
NumTrials.value = ntrials;
NumRewards.value = length(hit);
PercentCorrect.value = (length(hit) + length(cr))/ntrials;
HR.value = hr;
FAR.value = far;
HRMinusFAR.value = hr-far;
Dprime.value = dp;
%---------------------------------------------------
if (size(trials,1) >= 60)
fa = find(trials(end-59:end,1)==0 & trials(end-59:end,2)==0);
hit = find(trials(end-59:end,1)==1 & trials(end-59:end,2)==1);
miss = find(trials(end-59:end,1)==1 & trials(end-59:end,2)==0);
cr = find(trials(end-59:end,1)==0 & trials(end-59:end,2)==1);
num_s1 = length(hit) + length(miss);
num_s0 = length(fa) + length(cr);
ntrials = num_s1 + num_s0;
if isempty(fa)
far = 0;
else
far = length(fa)/num_s0;
end
if isempty(hit)
hr = 0;
else
hr = length(hit)/num_s1;
end
dp = dprime(hr, far, num_s1, num_s0);
Dprime60.value = dp;
end
case 'hide_show'
if strcmpi(value(analysis_show), 'hide')
set(value(analysisfig), 'Visible', 'off');
elseif strcmpi(value(analysis_show),'view')
set(value(analysisfig),'Visible','on');
end;
return;
case 'reinit'
currfig = gcf;
% Get the original GUI position and figure:
x = my_gui_info(1); y = my_gui_info(2); figure(my_gui_info(3));
delete(value(myaxes));
% Delete all SoloParamHandles who belong to this object and whose
% fullname starts with the name of this mfile:
delete_sphandle('owner', ['^@' class(obj) '$'], ...
'fullname', ['^' mfilename]);
% Reinitialise at the original GUI position and figure:
[x, y] = feval(mfilename, obj, 'init', x, y);
% Restore the current figure:
figure(currfig);
return;
end