-
Notifications
You must be signed in to change notification settings - Fork 4
/
HINT_GUI.m
407 lines (339 loc) · 13.9 KB
/
HINT_GUI.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
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
function varargout = HINT_GUI(varargin)
% HINT_GUI MATLAB code for HINT_GUI.fig
% HINT_GUI, by itself, creates a new HINT_GUI or raises the existing
% singleton*.
%
% H = HINT_GUI returns the handle to a new HINT_GUI or the handle to
% the existing singleton*.
%
% HINT_GUI('CALLBACK',hObject,eventData,handles,...) calls the local
% function named CALLBACK in HINT_GUI.M with the given input arguments.
%
% HINT_GUI('Property','Value',...) creates a new HINT_GUI or raises the
% existing singleton*. Starting from the left, property value pairs are
% applied to the GUI before HINT_GUI_OpeningFcn gets called. An
% unrecognized property name or invalid value makes property application
% stop. All inputs are passed to HINT_GUI_OpeningFcn via varargin.
%
% *See GUI Options on GUIDE's Tools menu. Choose "GUI allows only one
% instance to run (singleton)".
%
% INPUTS:
%
% 'xlabel': string, xlabel for figure. (default='Trial #')
%
% 'ylabel': string, 'ylabel' for figure. (default='SNR (dB)')
%
% 'ntrials': number of trials to play (sets axis information)
%
% 'score_labels': cell array, scoring labels used in scoring boxes. These
% default to 'correct' and 'incorrect'
%
% 'words': cell array, each cell is a string to score (usually a word)
%
% 'xdata': xdata for plotting in inset axes
%
% 'ydata': ydata for plotting in inset axes
%
% 'title': title for figure (upper left).
%
% 'isscored': bool array equal to the number of words in string. Each
% element corresponds to the same element of 'words'. A true
% value means it will be scored (scoring box visible). A
% false value means it will not be scored (scoring box
% invisible). (default = false for all elements)
%
% Development:
%
% 1) Need to add individual trial tracking data (e.g., id, words, etc.)
%
% Christopher W. Bishop (with help of GUIDE)
% University of Washington
% 5/14
% Edit the above text to modify the response to help HINT_GUI
% Last Modified by GUIDE v2.5 03-Oct-2014 15:00:31
% Begin initialization code - DO NOT EDIT
gui_Singleton = 1;
gui_State = struct('gui_Name', mfilename, ...
'gui_Singleton', gui_Singleton, ...
'gui_OpeningFcn', @HINT_GUI_OpeningFcn, ...
'gui_OutputFcn', @HINT_GUI_OutputFcn, ...
'gui_LayoutFcn', [] , ...
'gui_Callback', []);
if nargin && ischar(varargin{1})
gui_State.gui_Callback = str2func(varargin{1});
end
if nargout
[varargout{1:nargout}] = gui_mainfcn(gui_State, varargin{:});
else
gui_mainfcn(gui_State, varargin{:});
end
% End initialization code - DO NOT EDIT
% --- Executes just before HINT_GUI is made visible.
function HINT_GUI_OpeningFcn(hObject, eventdata, handles, varargin)
% This function has no output args, see OutputFcn.
% hObject handle to figure
% eventdata reserved - to be defined in a future version of MATLAB
% handles structure with handles and user data (see GUIDATA)
% varargin command line arguments to HINT_GUI (see VARARGIN)
% Choose default command line output for HINT_GUI
handles.output = hObject;
% Update handles structure
guidata(hObject, handles);
% Convert parameters to structure (easier to work with)
if length(varargin)>1
p=struct(varargin{:});
elseif length(varargin)==1
p=varargin{1};
elseif isempty(varargin)
p=struct();
end % if length ...
if ~isfield(p, 'words'), p.words=[]; end % no words by default
if ~isfield(p, 'isscored'), p.isscored=false(length(p.words),1); end % no scoring by default.
if ~isfield(p, 'xlabel'), p.xlabel='Trial #'; end
if ~isfield(p, 'ylabel'), p.ylabel='SNR (dB)'; end
if ~isfield(p, 'ntrials'), p.ntrials=20; end % set to 20 by default since we'll never have more than 20
if ~isfield(p, 'score_labels'), p.score_labels={'Correct', 'Incorrect'}; end
if ~isfield(p, 'xdata'), p.xdata=[]; end
if ~isfield(p, 'ydata'), p.ydata=[]; end
% Misc defaults
global max_words; % the maximum number of scorable words
global max_options; % the maximum number of options for each word.
max_words=10;
max_options=2;
% Set scoring labels
for i=1:max_words
end % for i=1:max_words
% Error check for p.words. GUI is designed to support 6 words, so throw an
% error if we have more than that
if length(p.words) > max_words, error('Too many words'); end
% Error check for p.score_labels. Figure only supports two scoring
% categories, so throw an error if we have too many
if length(p.score_labels) > max_options, error('Too many scoring labels'); end
% Quick check to make sure we have enough scoring information for all words
if length(p.isscored) ~= length(p.words), error('Scoring vector does not match number of words'); end
% Clear the current axes
% When test is restarted, it's important to clear the data stored on the
% axis from any previous text.
cla;
% Create axis labels
% Set XLabel, YLabel
set(get(handles.panel_plot, 'YLabel'), 'String', p.ylabel);
set(get(handles.panel_plot, 'XLabel'), 'String', p.xlabel);
% Change figure name (upper left corner)
set(handles.figure1, 'Name', p.title);
%% RESET GUI
% Reset words and scoring panels to default state (empty strings and
% invisible scoring panels).
for d=1:max_words
% Reset word values
set(handles.(['word' num2str(d) '_text']), 'String', '');
% Set all panels to invisible
set(handles.(['word' num2str(d) '_scoring']), 'Visible', 'off');
% Reset option labels and values
for o=1:max_options
set(handles.(['word' num2str(d) '_opt' num2str(o)]), 'String', p.score_labels{o});
set(handles.(['word' num2str(d) '_opt' num2str(o)]), 'Value', 0);
end % o=1:max_options
end % d=1:max_words
% Set domain
xlim([0 p.ntrials+1]);
%% ADD WORDS AND SCORING PANELS
% Add words to figure and enable scoring panels
for n=1:length(p.words)
% Add word to GUI
set(handles.(['word' num2str(n) '_text']), 'String', p.words{n});
% Add scoring panel
% - Recall that these are invisible by default
if p.isscored(n)
set(handles.(['word' num2str(n) '_scoring']), 'Visible', 'on');
end % if p.isscored(n)
end % for n=1:length(p.words)
%% UPDATE PLOT
% When plot data is provided, update the plot. This is useful for
% visualization (and debugging).
if ~isempty(p.xdata) && ~isempty(p.ydata)
lineplot2d(p.xdata, p.ydata, 'marker', 'o');
end % if ~
% UIWAIT makes HINT_GUI wait for user response (see UIRESUME)
% Waits for user input and response. Part of flow control for this
% HINT_modcheck_GUI.m.
uiwait(handles.figure1);
% --- Outputs from this function are returned to the command line.
function varargout = HINT_GUI_OutputFcn(hObject, eventdata, handles)
% varargout cell array for returning output args (see VARARGOUT);
% hObject handle to figure
% eventdata reserved - to be defined in a future version of MATLAB
% handles structure with handles and user data (see GUIDATA)
% Get default command line output from handles structure
varargout{1} = handles.output;
% Get score and response values matrices
[score, response_values]=HINT_GUI_score_responses(handles);
varargout{2}=score;
% Delete figure
% delete(handles.figure1);
% --- Executes on button press in radiobutton1.
function radiobutton1_Callback(hObject, eventdata, handles)
% hObject handle to radiobutton1 (see GCBO)
% eventdata reserved - to be defined in a future version of MATLAB
% handles structure with handles and user data (see GUIDATA)
% Hint: get(hObject,'Value') returns toggle state of radiobutton1
% --- Executes on button press in radiobutton2.
function radiobutton2_Callback(hObject, eventdata, handles)
% hObject handle to radiobutton2 (see GCBO)
% eventdata reserved - to be defined in a future version of MATLAB
% handles structure with handles and user data (see GUIDATA)
% Hint: get(hObject,'Value') returns toggle state of radiobutton2
% --- Executes on button press in button_next.
function button_next_Callback(hObject, eventdata, handles)
% hObject handle to button_next (see GCBO)
% eventdata reserved - to be defined in a future version of MATLAB
% handles structure with handles and user data (see GUIDATA)
% Error checking
[~, ~, iserror]=HINT_GUI_score_responses(handles);
% Resume UI.
if isequal(get(handles.figure1, 'waitstatus'), 'waiting') && ~iserror
uiresume(handles.figure1);
end % if isequal ...
% --- Executes on button press in record_checkbox.
function record_checkbox_Callback(hObject, eventdata, handles)
% hObject handle to record_checkbox (see GCBO)
% eventdata reserved - to be defined in a future version of MATLAB
% handles structure with handles and user data (see GUIDATA)
% Hint: get(hObject,'Value') returns toggle state of record_checkbox
% --- Executes when user attempts to close figure1.
function figure1_CloseRequestFcn(hObject, eventdata, handles)
% hObject handle to figure1 (see GCBO)
% eventdata reserved - to be defined in a future version of MATLAB
% handles structure with handles and user data (see GUIDATA)
% Hint: delete(hObject) closes the figure
% When we close the GUI, we want to resume the user interface (ui).
% Code gleaned from http://blogs.mathworks.com/videos/2010/02/12/advanced-getting-an-output-from-a-guide-gui/
if isequal(get(hObject, 'waitstatus'), 'waiting')
uiresume(hObject);
else
delete(hObject);
end %
% Scoring function
function [score, response_values, iserror]=HINT_GUI_score_responses(handles)
%% DESCRIPTION:
%
% Function to do some basic error checking and also generate scoring
% arrays.
%
% INPUT:
%
% handles: handles structure passed between everything
%
% OUTPUT:
%
% score: scored array. Scoring index goes like this
% -1: unscorable word (invisible scoring box)
% 0: No option selected (we need to implement some checks to
% make sure this doesn't happen).
% 1: Option 1 selected
% 2: Option 2 selected
% etc. ...
%
% note: code only tested with two options. will need to be
% checked thoroughly if more options are added.
%
% response_values: dxo matrix, where d is the number of words, and o
% is the number of options available for selection.
% This may not be necessary (CWB 5/14), but is here
% until CWB can test more thoroughly.
%
% iserror: bool, error flag. If set (true) then there's an error that
% needs to be addressed.
%
% Development:
%
% 1. Need to thoroughly test return values and response combinations.
%
% Christopher W. Bishop
% University of Washington
% 5/14
global max_words;
global max_options;
% Error checking
%
% 1. Make sure all scorable words have an option selected. If they do
% not, then tell the user that he (or she) needs to select an appropriate
% response.
%
% 2. Make sure multiple options are not selected
%
% 3. Make sure an option is selected for each (scorable) word.
% Initialize as unscorable
score=ones(max_words, 1).*-1;
% Initialize error flag
iserror=false;
for d=1:max_words
% Get the response for each option
for o=1:max_options
% Only gather responses if this is a "scored" word (meaning the
% scoring panel is visible)
if isequal(get(handles.(['word' num2str(d) '_scoring']), 'Visible'), 'on')
response_values(d, o)=get(handles.(['word' num2str(d) '_opt' num2str(o)]), 'Value');
else
response_values(d, o)=-1;
end % if isequal
end % for o=1:max_opts
% Error checking must be done when NEXT is clicked. So, we need to
% assume errors don't make it through to the output level.
%
% But, just to make sure, here's a basic check to make sure we don't
% have multiple selections or no selections
if numel(find(response_values(d, :)~=0)) ~= 1 && isequal(get(handles.(['word' num2str(d) '_scoring']), 'Visible'), 'on')
errordlg(['Incorrect number of responses selected for word ' num2str(d)]);
iserror=true;
break;
elseif isequal(get(handles.(['word' num2str(d) '_scoring']), 'Visible'), 'on')
% Only overwrite the '-1' place holder if the word should be
% scored.
score(d)=find(response_values(d,:)==1, 1, 'first');
end % if numel
end % for d=1:max_words
% --- Executes on button press in button_allcorrect.
function button_allcorrect_Callback(hObject, eventdata, handles)
% hObject handle to button_allcorrect (see GCBO)
% eventdata reserved - to be defined in a future version of MATLAB
% handles structure with handles and user data (see GUIDATA)
set_radio_buttons(hObject, eventdata, handles, 1);
% --- Executes on button press in button_allincorrect.
function button_allincorrect_Callback(hObject, eventdata, handles)
% hObject handle to button_allincorrect (see GCBO)
% eventdata reserved - to be defined in a future version of MATLAB
% handles structure with handles and user data (see GUIDATA)
set_radio_buttons(hObject, eventdata, handles, 2);
function set_radio_buttons(hObject, eventdata, handles, button_number)
%% DESCRIPTION:
%
% Function to set radio buttons a radio button in a scoring box. Values for
% this scoring GUI range from [1 - 2].
%
% INPUT:
%
% hObject ...
% eventadata ...
% handles ...
%
% button_number: which radio button in the word scoring panel to set.
%
% OUTPUT:
%
% None
%
% Christopher W Bishop
% University of Washington
% 10/14
% Get global
global max_words;
% When this button is clicked, we'll set all radio buttons to the first
% option (typically "correct").
for i=1:max_words
% Set first option to true in all visible scoring boxes
if isequal(get(handles.(['word' num2str(i) '_scoring']), 'Visible'), 'on')
set(handles.(['word' num2str(i) '_opt' num2str(button_number)]), 'Value', 1)
end %
end % for i=1:max_words