-
Notifications
You must be signed in to change notification settings - Fork 3
/
nback_matlab.m
1371 lines (1278 loc) · 64.5 KB
/
nback_matlab.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
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
453
454
455
456
457
458
459
460
461
462
463
464
465
466
467
468
469
470
471
472
473
474
475
476
477
478
479
480
481
482
483
484
485
486
487
488
489
490
491
492
493
494
495
496
497
498
499
500
501
502
503
504
505
506
507
508
509
510
511
512
513
514
515
516
517
518
519
520
521
522
523
524
525
526
527
528
529
530
531
532
533
534
535
536
537
538
539
540
541
542
543
544
545
546
547
548
549
550
551
552
553
554
555
556
557
558
559
560
561
562
563
564
565
566
567
568
569
570
571
572
573
574
575
576
577
578
579
580
581
582
583
584
585
586
587
588
589
590
591
592
593
594
595
596
597
598
599
600
601
602
603
604
605
606
607
608
609
610
611
612
613
614
615
616
617
618
619
620
621
622
623
624
625
626
627
628
629
630
631
632
633
634
635
636
637
638
639
640
641
642
643
644
645
646
647
648
649
650
651
652
653
654
655
656
657
658
659
660
661
662
663
664
665
666
667
668
669
670
671
672
673
674
675
676
677
678
679
680
681
682
683
684
685
686
687
688
689
690
691
692
693
694
695
696
697
698
699
700
701
702
703
704
705
706
707
708
709
710
711
712
713
714
715
716
717
718
719
720
721
722
723
724
725
726
727
728
729
730
731
732
733
734
735
736
737
738
739
740
741
742
743
744
745
746
747
748
749
750
751
752
753
754
755
756
757
758
759
760
761
762
763
764
765
766
767
768
769
770
771
772
773
774
775
776
777
778
779
780
781
782
783
784
785
786
787
788
789
790
791
792
793
794
795
796
797
798
799
800
801
802
803
804
805
806
807
808
809
810
811
812
813
814
815
816
817
818
819
820
821
822
823
824
825
826
827
828
829
830
831
832
833
834
835
836
837
838
839
840
841
842
843
844
845
846
847
848
849
850
851
852
853
854
855
856
857
858
859
860
861
862
863
864
865
866
867
868
869
870
871
872
873
874
875
876
877
878
879
880
881
882
883
884
885
886
887
888
889
890
891
892
893
894
895
896
897
898
899
900
901
902
903
904
905
906
907
908
909
910
911
912
913
914
915
916
917
918
919
920
921
922
923
924
925
926
927
928
929
930
931
932
933
934
935
936
937
938
939
940
941
942
943
944
945
946
947
948
949
950
951
952
953
954
955
956
957
958
959
960
961
962
963
964
965
966
967
968
969
970
971
972
973
974
975
976
977
978
979
980
981
982
983
984
985
986
987
988
989
990
991
992
993
994
995
996
997
998
999
1000
function handles = nback_matlab
%% INFORMATION:
%
% -Keep the 'nback_matlab.m' function within the same folder as the subfolder
% 'Audio', which contains audio files required for the program to run. As
% long as 'nback_matlab.m' is on Matlab's path, the program will handle
% adding the audio files to the path automatically.
%
% -A 'UserData' subfolder will be written to the same location as
% 'nback_matlab.m the first time the program is run. User performance
% data will be stored in a .mat file within this folder
% ('user_data.mat'). Also, whenever the program closes, the
% 'nback_matlab_settings.txt' file will be updated with the user's most
% recent preferences (this will be loaded upon program reboot).
% -the user_data.mat file contains a variable 'summaryStats' that
% summarizes A' (see below), hit rate, false alarm rate, and lure error
% rate for each stimuli type (position, sound, color); it also contains a
% 'trialData' cell array that shows actual user responses for every trial
% (rows of table) of each round of n-back played (cells)
%
% *Scoring: A' (Discrimination Index), similar to d'
% H = Hit Rate (hits / # signal trials),
% F = False-positive Rate (false pos / # noise trials)
% aPrime = .5 + sign(H - F) * ((H - F)^2 + abs(H - F)) / (4 * max(H, F) - 4 * H * F);
%
% A' references:
% Snodgrass, J. G., & Corwin, J. (1988). Pragmatics of measuring recognition
% memory: applications to dementia and amnesia. Journal of Experimental
% Psychology: General, 117(1), 34.
%
% Stanislaw, H., & Todorov, N. (1999). Calculation of signal detection theory
% measures. Behavior research methods, instruments, & computers, 31(1),
% 137-149.
%
% *For mathematical formula, see Stanislaw & Todorov (1999, p. 142)
%
% *Default Settings:
% nback = 2; % nBack level
% percLure = .2; % percentage of non-match trials to be converted to
% "lure" or interference trials (a lure is n-back +/- 1, requiring
% engagement of executive control to avoid errors)
% sound_on = 1; % sound-type nBack: 1 (on), 0 (off)
% position_on = 1; % position-type nBack: 1 (on), 0 (off)
% color_on = 0; % color-type nBack: 1 (on), 0 (off)
% completely_random = 0; % off (0), on (1) (if on, next 3 settings are irrelevant)
% n_positionHits = 4; % control # of matches for position
% n_soundHits = 4; % control # of matches for sound
% n_colorHits = 4; % control # of matches for color
% advance_thresh = .9; % minimum score (A') required to advance automatically to next nBack level;
% fallback_thresh = .75; % score (A') below which one automatically regresses to previous nBack level;
% nTrials = nback + 20; % # trials
% trial_time = 2.4; % seconds
% volume_factor = 1; % Default: 1 (no change); >1 = increase volume; <1 = decrease volume
% sound_type = 1; % use Numbers-Female (1), Numbers-Male (2), Letters-Female1 (3), or Letters-Female2 (4)
% enable_applause = 1; % 1 (on) or 0 (off); applause on advance to next n-back level
% enable_boos = 0; % 1 (on) or 0 (off); comical boos if fallback to previous n-back level
% realtime_feedback = 1; % 1 (on) or 0 (off); highlight labels red/green based on accuracy
% figure_window_feedback = 1; % 1 (on) or 0 (off); display hits, misses, false alarms in figure window upon completion
% command_line_feedback = 1; % 1 (on) or 0 (off); display hits, misses, false alarms in command window upon completion
% show_remaining = 1; % 1 (on) or 0 (off); show remaining trials
% background_color_scheme = 1; % black (1), white (2)
%
% *Author: Elliot A. Layden (2017-18),
% at The Environmental Neuroscience Laboratory, The University of Chicago
%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
%% Hotkey Designations:
startSessionKey = 'space';
positionMatchKey = 'a';
soundMatchKey = 'l';
colorMatchKey = 'j';
stopRunningKey = 'escape';
%% ------------------------ Begin ------------------------
customizable = {'nback','percLure','sound_on','position_on','color_on','completely_random',...
'n_soundHits','n_positionHits','n_colorHits','advance_thresh',...
'fallback_thresh','nTrials','trial_time','volume_factor',...
'sound_type','enable_applause','enable_boos','realtime_feedback',...
'command_line_feedback','figure_window_feedback','show_remaining',...
'background_color_scheme'};
% Initialize Global Variables:
curr_running = 0; stop_running = 0; ix = 1; canResize = false;
position_mem = []; color_mem = []; sound_mem = [];
position_match_vec = []; sound_match_vec = []; color_match_vec = [];
user_position_match = []; user_sound_match = []; user_color_match = [];
position_lures_vec = []; sound_lures_vec = []; color_lures_vec = [];
advance_thresh = []; fallback_thresh = [];
figure_window_feedback = []; command_line_feedback = []; volume_factor = [];
h_pos_feedback1_pos = []; h_pos_feedback2_pos = [];
h_color_feedback1_pos = []; h_color_feedback2_pos = [];
h_sound_feedback1_pos = []; h_sound_feedback2_pos = [];
percLure = .2; timerVal = 0; times = []; extraKeys = {};
% Initialize object handles:
h_title = 10.384372; h_volume = 28.1717839;
h_pos_feedback1 = 10.384372; h_pos_feedback2 = 10.384372;
h_sound_feedback1 = 10.384372; h_sound_feedback2 = 10.384372;
h_color_feedback1 = 10.384372; h_color_feedback2 = 10.384372;
square_width = .2;
positions = repmat([.05,.05,square_width,square_width],9,1);
% Get script path and subfolders:
script_fullpath = mfilename('fullpath');
[script_path,~,~] = fileparts(script_fullpath);
addpath(genpath(script_path))
audio_path = fullfile(script_path,'Audio');
audio_subfolders = {fullfile(audio_path,'numbers-female'),fullfile(audio_path,'numbers-male'),...
fullfile(audio_path,'letters-female1'),fullfile(audio_path,'letters-female2')};
% Get Settings:
get_settings;
% Calculate Parameters
[~,nBack_spec] = min(abs((1:20)-nback));
poss_lures = 0:.05:1;
[~,lure_spec] = min(abs(poss_lures-percLure));
trial_num_opts = 15:5:100; % nTrials
n_trial_num_opts = length(trial_num_opts);
if nTrials==nback+20
trial_num_spec = 1;
else trial_num_spec = 1+min(abs(trial_num_opts-nTrials));
end
trial_time_opts = 1:.2:4; % seconds;
n_trial_time_opts = length(trial_time_opts);
[~,trial_time_spec] = min(abs(trial_time_opts-trial_time));
% Appearance Customization:
if background_color_scheme==1
txt_color = ones(1,3);
background_color = zeros(1,3);
colors = {'y','m','c','r','g','b','w'};
elseif background_color_scheme==2
txt_color = zeros(1,3);
background_color = ones(1,3);
colors = {'y','m','c','r','g','b','k'};
end
% Load Main Audio:
audio_dat = struct('sound',cell(1,4),'Fs',cell(1,4),'nSound',cell(1,4));
for i = 1:4
listing = dir(audio_subfolders{i});
nSound = length(listing)-2;
audio_dat(i).sound = cell(1,nSound);
audio_dat(i).Fs = cell(1,nSound);
audio_dat(i).nSound = nSound;
for j = 1:nSound
[audio_dat(i).sound{j},audio_dat(i).Fs{j}] = audioread(fullfile(audio_subfolders{i},listing(j+2).name));
end
end
% Load Reaction Sounds (Applause/Boos):
[applause_dat, Fs_applause] = audioread(fullfile(audio_path,'applause.mp3'));
[boo_dat, Fs_boo] = audioread(fullfile(audio_path,'boo.mp3'));
% Initialize Figure:
handles.figure = figure('menubar','none','color',background_color,'numbertitle',...
'off','name',['nback_matlab: (',num2str(nback),'-Back)'],'units','norm',...
'Position',[.271,.109,.488,.802],'ResizeFcn',@resizeScreen);
handles.axes1 = gca; set(handles.axes1,'Position',[0,0,1,1],'XLim',[0,1],...
'YLim',[0,1],'Visible','off');
h_title = annotation('textbox','String','','FontName','Helvetica','FontSize',14,...
'Position',[.4,.955,.2,.05],'Color',txt_color,'HorizontalAlignment','center',...
'FontWeight','bold','EdgeColor','none');
%% Menus:
% File Menu:
file_menu = uimenu(handles.figure,'Label','File');
% uimenu(file_menu,'Label','Progress Report','Callback',@show_progress);
uimenu(file_menu,'Label','Exit','Callback',@close_nback_matlab);
% Session Menu:
session_menu = uimenu(handles.figure,'Label','Session');
% N-Back Level:
nBack_num_menu = uimenu(session_menu,'Label','N-Back Level');
h_nBack = zeros(1,20);
for i = 1:20
h_nBack(i) = uimenu(nBack_num_menu,'Label',sprintf('%02g',i),'Callback',{@change_nBack,i});
end; set(h_nBack(nBack_spec),'Checked','on')
% Percent Lures:
percLure_menu = uimenu(session_menu,'Label','Percent Lures/Interference');
h_lures = zeros(1,21);
for i = 1:21
h_lures(i) = uimenu(percLure_menu,'Label',sprintf('%02g',poss_lures(i)),'Callback',{@change_lures,i});
end; set(h_lures(lure_spec),'Checked','on')
% Stimuli Type(s) Menu:
nBack_type_menu = uimenu(session_menu,'Label','Stimuli Type(s)');
if position_on
types_menu(1) = uimenu(nBack_type_menu,'Label','Position','Checked','on','Callback',{@change_types,1});
else types_menu(1) = uimenu(nBack_type_menu,'Label','Position','Checked','off','Callback',{@change_types,1});
end
if sound_on
types_menu(2) = uimenu(nBack_type_menu,'Label','Sound','Checked','on','Callback',{@change_types,2});
else types_menu(2) = uimenu(nBack_type_menu,'Label','Sound','Checked','off','Callback',{@change_types,2});
end
if color_on
types_menu(3) = uimenu(nBack_type_menu,'Label','Color','Checked','on','Callback',{@change_types,3});
else types_menu(3) = uimenu(nBack_type_menu,'Label','Color','Checked','off','Callback',{@change_types,3});
end
trial_num_menu = uimenu(session_menu,'Label','# Trials');
h_trial_num = zeros(1,n_trial_num_opts+1);
h_trial_num(1) = uimenu(trial_num_menu,'Label','20 + N (default)','Callback',{@change_trial_num,1});
for i = 2:n_trial_num_opts+1
h_trial_num(i) = uimenu(trial_num_menu,'Label',sprintf('%1g',trial_num_opts(i-1)),'Callback',{@change_trial_num,i});
end; set(h_trial_num(trial_num_spec),'Checked','on')
trial_length_menu = uimenu(session_menu,'Label','Trial Length');
h_trial_times = zeros(1,n_trial_time_opts);
for i = 1:n_trial_time_opts
h_trial_times(i) = uimenu(trial_length_menu,'Label',sprintf('%1.1f seconds',trial_time_opts(i)),'Callback',{@change_trial_time,i});
end; set(h_trial_times(trial_time_spec),'Checked','on')
advanced_menu = uimenu(session_menu,'Label','Advanced');
num_hits_menu = uimenu(advanced_menu,'Label','# Matches');
sound_matches_menu = uimenu(num_hits_menu,'Label','# Sound Matches');
n_poss = round(.6*nTrials);
h_n_sound_matches = zeros(1,n_poss);
for i = 1:n_poss
h_n_sound_matches(i) = uimenu(sound_matches_menu,'Label',sprintf('%02g',i),'Callback',{@change_sound_matches,i});
end
set(h_n_sound_matches(n_soundHits),'Checked','on')
position_matches_menu = uimenu(num_hits_menu,'Label','# Position Matches');
h_n_position_matches = zeros(1,n_poss);
for i = 1:n_poss
h_n_position_matches(i) = uimenu(position_matches_menu,'Label',sprintf('%02g',i),'Callback',{@change_position_matches,i});
end
set(h_n_position_matches(n_positionHits),'Checked','on')
color_matches_menu = uimenu(num_hits_menu,'Label','# Color Matches');
h_n_color_matches = zeros(1,n_poss);
for i = 1:n_poss
h_n_color_matches(i) = uimenu(color_matches_menu,'Label',sprintf('%02g',i),'Callback',{@change_color_matches,i});
end
set(h_n_color_matches(n_colorHits),'Checked','on')
if completely_random
uimenu(num_hits_menu,'Label',...
'Completely Random','Checked','on','Callback',@change_completely_random);
else
uimenu(num_hits_menu,'Label',...
'Completely Random','Checked','off','Callback',@change_completely_random);
end
advance_fallback_menu = uimenu(advanced_menu,'Label','Advance/Fallback');
advance_menu = uimenu(advance_fallback_menu,'Label','Advance Threshold');
advance_thresholds = 1:-0.02:0.80;
h_advances = zeros(1,length(advance_thresholds));
for i = 1:length(advance_thresholds)
h_advances(i) = uimenu(advance_menu,'Label',sprintf('%g%',advance_thresholds(i)),'Callback',{@change_advance_thresh,i});
end
[~,which_advance] = min(abs(advance_thresholds-advance_thresh));
set(h_advances(which_advance),'Checked','on')
set(h_advances(6),'Label',[sprintf('%g%',advance_thresholds(6)),' (default)']);
fallback_menu = uimenu(advance_fallback_menu,'Label','Fallback Threshold');
fallback_thresholds = .80:-.05:.50;
h_fallbacks = zeros(1,length(fallback_thresholds));
for i = 1:length(fallback_thresholds)
h_fallbacks(i) = uimenu(fallback_menu,'Label',sprintf('%g%',fallback_thresholds(i)),'Callback',{@change_fallback_thresh,i});
end
[~,which_fallback] = min(abs(fallback_thresholds-fallback_thresh));
set(h_fallbacks(which_fallback),'Checked','on')
set(h_fallbacks(2),'Label',[sprintf('%g%',fallback_thresholds(2)),' (default)']);
feedback_menu = uimenu(handles.figure,'Label','Feedback');
if show_remaining
uimenu(feedback_menu,'Label','Show Remaining Trials','Checked','on','Callback',@change_show_remaining);
else uimenu(feedback_menu,'Label','Show Remaining Trials','Checked','off','Callback',@change_show_remaining);
end
if realtime_feedback
uimenu(feedback_menu,'Label','Realtime Feedback','Checked','on','Callback',@change_realtime_feedback);
else uimenu(feedback_menu,'Label','Realtime Feedback','Checked','off','Callback',@change_realtime_feedback);
end
if figure_window_feedback
uimenu(feedback_menu,'Label','Results in GUI','Checked','on','Callback',@change_figure_feedback);
else uimenu(feedback_menu,'Label','Results in GUI','Checked','off','Callback',@change_figure_feedback);
end
if command_line_feedback
uimenu(feedback_menu,'Label','Command Line Results','Checked','on','Callback',@change_cmd_feedback);
else uimenu(feedback_menu,'Label','Command Line Results','Checked','off','Callback',@change_cmd_feedback);
end
sound_settings_menu = uimenu(handles.figure,'Label','Sounds');
uimenu(sound_settings_menu,'Label','Volume','Callback',@change_volume);
sound_type_menu = uimenu(sound_settings_menu,'Label','Type');
h_letters = uimenu(sound_type_menu,'Label','Letters');
h_sound_types(3) = uimenu(h_letters,'Label','Female Voice 1','Callback',{@change_sound_types,3});
h_sound_types(4) = uimenu(h_letters,'Label','Female Voice 2','Callback',{@change_sound_types,4});
h_numbers = uimenu(sound_type_menu,'Label','Numbers');
h_sound_types(1) = uimenu(h_numbers,'Label','Female Voice','Callback',{@change_sound_types,1});
h_sound_types(2) = uimenu(h_numbers,'Label','Male Voice','Callback',{@change_sound_types,2});
set(h_sound_types(sound_type),'Checked','on')
reactions_menu = uimenu(sound_settings_menu,'Label','Reactions');
if enable_applause
uimenu(reactions_menu,'Label','Applause','Checked','on','Callback',@change_applause_setting);
else uimenu(reactions_menu,'Label','Applause','Checked','off','Callback',@change_applause_setting);
end
if enable_boos
uimenu(reactions_menu,'Label','Boos','Checked','on','Callback',@change_boos_setting);
else uimenu(reactions_menu,'Label','Boos','Checked','off','Callback',@change_boos_setting);
end
appearance_menu = uimenu(handles.figure,'Label','Appearance');
background_menu = uimenu(appearance_menu,'Label','Background');
if background_color_scheme==1
h_background_menu1 = uimenu(background_menu,'Label','Black','Checked','on','Callback',{@change_background,1});
h_background_menu2 = uimenu(background_menu,'Label','White','Callback',{@change_background,2});
txt_color = ones(1,3);
elseif background_color_scheme==2
h_background_menu1 = uimenu(background_menu,'Label','Black','Callback',{@change_background,1});
h_background_menu2 = uimenu(background_menu,'Label','White','Checked','on','Callback',{@change_background,2});
txt_color = zeros(1,3);
else warning('''background_color'' should be either integer 1 (black) or 2 (white)')
h_background_menu1 = uimenu(background_menu,'Label','Black','Checked','on','Callback',{@change_background,1});
h_background_menu2 = uimenu(background_menu,'Label','White','Callback',{@change_background,2});
txt_color = ones(1,3);
end
%% Add other display elements (gridlines, rectangle, etc.):
% Gridlines:
minMeasure = .05; maxMeasure = .95; one_third = .3497; two_thirds = .6503;
h_grid_lines = zeros(1,4);
h_grid_lines(1) = annotation('line','X',[one_third,one_third],'Y',[minMeasure,maxMeasure],'Color',txt_color,'LineWidth',1);
h_grid_lines(2) = annotation('line','X',[two_thirds,two_thirds],'Y',[minMeasure,maxMeasure],'Color',txt_color,'LineWidth',1);
h_grid_lines(3) = annotation('line','X',[minMeasure,maxMeasure],'Y',[two_thirds,two_thirds],'Color',txt_color,'LineWidth',1);
h_grid_lines(4) = annotation('line','X',[minMeasure,maxMeasure],'Y',[one_third,one_third],'Color',txt_color,'LineWidth',1);
% Initialize Match Button Text and Rectangle:
handles.h_rect = rectangle('Parent',handles.axes1,'Position',...
[.05,.05,square_width,square_width],'Curvature',[.2,.2],'FaceColor',...
'blue','Visible','off');
h_txt_begin = annotation('textbox',[.37,.48,.26,.04],'String',...
['Press ',startSessionKey,sprintf(' \nto begin')],...
'Color',txt_color,'HorizontalAlignment','center','VerticalAlignment',...
'middle','FontSize',14,'FontWeight','bold','EdgeColor','none');
h_txt_pos = text('position',[.04,.01],'String',['Position Match: ''',positionMatchKey,''''],...
'Color',txt_color,'HorizontalAlignment','center','VerticalAlignment','top',...
'FontSize',13,'FontWeight','normal','Visible','off','EdgeColor','none');
h_txt_color = text('position',[.35,.01],'String',['Color Match: ''',colorMatchKey,''''],...
'Color',txt_color,'HorizontalAlignment','center','VerticalAlignment','top',...
'FontSize',13,'FontWeight','normal','Visible','off','EdgeColor','none');
h_txt_sound = text('position',[.658,.01],'String',['Sound Match: ''',soundMatchKey,''''],...
'Color',txt_color,'HorizontalAlignment','center','VerticalAlignment','top',...
'FontSize',13,'FontWeight','normal','Visible','off','EdgeColor','none');
if position_on; set(h_txt_pos,'Visible','on'); end
if color_on; set(h_txt_color,'Visible','on'); end
if sound_on; set(h_txt_sound,'Visible','on'); end
% Declare Figure Callbacks:
set(handles.figure,'WindowKeyPressFcn',@keypress_callback);
set(handles.figure,'CloseRequestFcn',@close_nback_matlab)
% Resize Figure function:
canResize = true;
resizeScreen;
%% Run Function:
function run_session
extraKeys = cell(nTrials,1); curr_running = 1;
% Get Trial Times:
targetTimes = linspace(1,trial_time * (nTrials-1) + 1, nTrials);
pause(1 - (toc(timerVal)-0));
disableMenus; % disallow users from toggling settings during play
if ishandle(h_pos_feedback1)
delete(h_pos_feedback1); delete(h_pos_feedback2)
end
if ishandle(h_sound_feedback1)
delete(h_sound_feedback1); delete(h_sound_feedback2)
end
if ishandle(h_color_feedback1)
delete(h_color_feedback1); delete(h_color_feedback2)
end
% START TRIALS:
ix = 0; times = zeros(nTrials,1);
while ix<nTrials && ~stop_running
ix = ix + 1; times(ix) = toc(timerVal);
if realtime_feedback
set(h_txt_pos,'Color',txt_color)
set(h_txt_sound,'Color',txt_color)
set(h_txt_color,'Color',txt_color)
end
if show_remaining
set(h_title,'String',num2str(nTrials-ix))
end
tic
if position_on
set(handles.h_rect,'Position',positions(position_mem(ix),:),'Visible','on')
end
if color_on
set(handles.h_rect,'FaceColor',colors{color_mem(ix)})
end
if sound_on
sound(audio_dat(sound_type).sound{sound_mem(ix)}*volume_factor,audio_dat(sound_type).Fs{sound_mem(ix)})
end
if abs(toc(timerVal)-targetTimes(ix)) < .5
pause(trial_time - (toc(timerVal)-targetTimes(ix)));
else
pause(trial_time - sign(toc(timerVal)-targetTimes(ix))*.5);
end
end
curr_running = 0; set(handles.h_rect,'Visible','off')
set(h_txt_begin,'Visible','on'); set(h_title,'String','')
set(h_txt_pos,'Color',txt_color); set(h_txt_sound,'Color',txt_color)
set(h_txt_color,'Color',txt_color)
% Calculate Score:
if ~stop_running
% Position Stats:
position_hits = sum((position_match_vec+user_position_match)==2);
position_false = sum((position_match_vec-user_position_match)==-1);
position_lure_errors = sum((position_lures_vec+user_position_match)==2)/sum(position_lures_vec);
H_pos = position_hits / n_positionHits; F_pos = position_false / (nTrials - n_positionHits);
pos_score = .5 + sign(H_pos - F_pos) * ((H_pos - F_pos)^2 + abs(H_pos - F_pos)) / (4 * max(H_pos, F_pos) - 4 * H_pos * F_pos);
position_stats = cell(5,2);
position_stats(1:5,1) = {'Position','A'':','Hits:','False-Alarms:','Lure Errors:'};
position_stats{2,2} = num2str(round(pos_score,2));
position_stats{3,2} = [num2str(round(100*H_pos)),'%'];
position_stats{4,2} = [num2str(round(100*F_pos)),'%'];
position_stats{5,2} = [num2str(round(100*position_lure_errors)),'%'];
% Sound Stats:
sound_hits = sum((sound_match_vec+user_sound_match)==2);
sound_false = sum((sound_match_vec-user_sound_match)==-1);
sound_lure_errors = sum((sound_lures_vec+user_sound_match)==2)/sum(sound_lures_vec);
H_sound = sound_hits / n_soundHits; F_sound = sound_false / (nTrials - n_soundHits);
sound_score = .5 + sign(H_sound - F_sound) * ((H_sound - F_sound)^2 + abs(H_sound - F_sound)) / (4 * max(H_sound, F_sound) - 4 * H_sound * F_sound);
sound_stats = cell(5,2);
sound_stats(1:5,1) = {'Sound','A'':','Hits:','False-Alarms:','Lure Errors:'};
sound_stats{2,2} = num2str(round(sound_score,2));
sound_stats{3,2} = [num2str(round(100*H_sound)),'%'];
sound_stats{4,2} = [num2str(round(100*F_sound)),'%'];
sound_stats{5,2} = [num2str(round(100*sound_lure_errors)),'%'];
% Color Stats:
color_hits = sum((color_match_vec+user_color_match)==2);
color_false = sum((color_match_vec-user_color_match)==-1);
color_lure_errors = sum((color_lures_vec+user_color_match)==2)/sum(color_lures_vec);
H_color = color_hits / n_colorHits; F_color = color_false / (nTrials - n_colorHits);
color_score = .5 + sign(H_color - F_color) * ((H_color - F_color)^2 + abs(H_color - F_color)) / (4 * max(H_color, F_color) - 4 * H_color * F_color);
color_stats = cell(5,2);
color_stats(1:5,1) = {'Color','A'':','Hits:','False-Alarms:','Lure Errors:'};
color_stats{2,2} = num2str(round(color_score,2));
color_stats{3,2} = [num2str(round(100*H_color,1)),'%'];
color_stats{4,2} = [num2str(round(100*F_color,1)),'%'];
color_stats{5,2} = [num2str(round(100*color_lure_errors)),'%'];
% Command-line Feedback:
if command_line_feedback
if position_on && sound_on && color_on
session_stats = [position_stats,sound_stats,color_stats];
elseif position_on && sound_on && ~color_on
session_stats = [position_stats,sound_stats];
elseif position_on && ~sound_on && ~color_on
session_stats = position_stats;
elseif ~position_on && sound_on && ~color_on
session_stats = sound_stats;
elseif ~position_on && sound_on && color_on
session_stats = [sound_stats,color_stat];
elseif position_on && ~sound_on && color_on
session_stats = [position_stats,color_stats];
elseif ~position_on && ~sound_on && color_on
session_stats = color_stats;
else return;
end
disp(session_stats)
end
% Write data:
user_position_match = user_position_match==1;
user_sound_match = user_sound_match==1;
user_color_match = user_color_match==1;
writeData(pos_score, position_lure_errors, H_pos, F_pos, ...
sound_score, sound_lure_errors, H_sound, F_sound, ...
color_score, color_lure_errors, H_color, F_color, ...
(1:nTrials)', times, position_match_vec', position_lures_vec', ...
user_position_match', position_mem', sound_match_vec', sound_lures_vec', ...
user_sound_match', sound_mem', color_match_vec', color_lures_vec', ...
user_color_match', color_mem',extraKeys)
% Check if Advance:
advance_vec = [(pos_score >= advance_thresh),(sound_score >= advance_thresh),(color_score >= advance_thresh)];
fallback_vec = [(pos_score <= fallback_thresh),(sound_score <= fallback_thresh),(color_score <= fallback_thresh)];
if all(advance_vec(logical([position_on,sound_on,color_on])))
if command_line_feedback
disp('Congratulations, you have been advanced to the next nBack level!')
end
nback = nback+1;
if get(h_trial_num(1),'checked')
nTrials = nTrials + 1;
end
set(handles.figure,'name',['nback_matlab: (',num2str(nback),'-Back)'])
set(h_nBack(nback-1),'Checked','off'); set(h_nBack(nback),'Checked','on');
if enable_applause; sound(applause_dat,Fs_applause); end
if figure_window_feedback
figure_feedback_color = 'g';
end
elseif any(fallback_vec(logical([position_on,sound_on,color_on])))
if nback>1;
nback = nback-1;
if get(h_trial_num(1),'checked')
nTrials = nTrials - 1;
end
if command_line_feedback
disp('Good effort - nBack level lowered.')
end
set(handles.figure,'name',['nback_matlab: (',num2str(nback),'-Back)'])
set(h_nBack(nback+1),'Checked','off'); set(h_nBack(nback),'Checked','on');
else if command_line_feedback; disp('Good effort.'); end
end
if enable_boos; sound(boo_dat,Fs_boo); end
if figure_window_feedback
figure_feedback_color = 'r';
end
else
if command_line_feedback; disp('Good score - keep training!'); end
if figure_window_feedback
if background_color_scheme==1
figure_feedback_color = 'w';
elseif background_color_scheme==2
figure_feedback_color = 'k';
end
end
end
if figure_window_feedback
if position_on
main_char = char('Position','A'':','Hits:','False-Alarms:','Lure Errors:');
char2 = char('',position_stats{2,2},position_stats{3,2},position_stats{4,2},position_stats{5,2});
h_pos_feedback1 = text('String',main_char,'FontName','Helvetica','FontSize',13,...
'Position',h_pos_feedback1_pos,'Color',figure_feedback_color,...
'FontWeight','bold','EdgeColor','none','HorizontalAlignment','left');
h_pos_feedback2 = text('String',char2,'FontName','Helvetica','FontSize',13,...
'Position',h_pos_feedback2_pos,'Color',figure_feedback_color,'HorizontalAlignment','right',...
'FontWeight','normal','EdgeColor','none');
end
if sound_on
main_char = char('Sound','A'':','Hits:','False-Alarms:','Lure Errors:');
char2 = char('',sound_stats{2,2},sound_stats{3,2},sound_stats{4,2},sound_stats{5,2});
h_sound_feedback1 = text('String',main_char,'FontName','Helvetica','FontSize',13,...
'Position',h_sound_feedback1_pos,'Color',figure_feedback_color,...
'FontWeight','bold','EdgeColor','none');
h_sound_feedback2 = text('String',char2,'FontName','Helvetica','FontSize',13,...
'Position',h_sound_feedback2_pos,'Color',figure_feedback_color,'HorizontalAlignment','right',...
'FontWeight','normal','EdgeColor','none');
end
if color_on
main_char = char('Color','A'':','Hits:','False-Alarms:','Lure Errors:');
char2 = char('',color_stats{2,2},color_stats{3,2},color_stats{4,2},color_stats{5,2});
h_color_feedback1 = text('String',main_char,'FontName','Helvetica','FontSize',13,...
'Position',h_color_feedback1_pos,'Color',figure_feedback_color,...
'FontWeight','bold','EdgeColor','none');
h_color_feedback2 = text('String',char2,'FontName','Helvetica','FontSize',13,...
'Position',h_color_feedback2_pos,'Color',figure_feedback_color,'HorizontalAlignment','right',...
'FontWeight','normal','EdgeColor','none');
end
end
else stop_running = 0;
end
enableMenus;
end
% Key Press Callback:
function keypress_callback(~,which_key,~)
switch which_key.Key
case startSessionKey
if ~curr_running
timerVal = tic;
curr_running = 1; set(h_txt_begin,'Visible','off')
if completely_random
position_mem = randi(9,[1,nTrials]);
color_mem = randi(7,[1,nTrials]);
sound_mem = randi(audio_dat(sound_type).nSound,[1,nTrials]);
else
% Generate Idx:
wasSuccess = false;
while ~wasSuccess
[position_mem, position_match_vec, position_lures_vec, wasSuccess] = generateIdx(nTrials, nback, n_positionHits, percLure, 9);
end; wasSuccess = false;
while ~wasSuccess
[sound_mem, sound_match_vec, sound_lures_vec, wasSuccess] = generateIdx(nTrials, nback, n_soundHits, percLure, audio_dat(sound_type).nSound);
end; wasSuccess = false;
while ~wasSuccess
[color_mem, color_match_vec, color_lures_vec, wasSuccess] = generateIdx(nTrials, nback, n_colorHits, percLure, 7);
end
user_position_match = nan(1, nTrials);
user_sound_match = nan(1, nTrials);
user_color_match = nan(1, nTrials);
end
run_session
end
case positionMatchKey
if curr_running
user_position_match(ix) = 1;
if realtime_feedback
if position_match_vec(ix)
set(h_txt_pos,'Color',[0,1,0])
else
set(h_txt_pos,'Color',[1,0,0])
end
end
end
case colorMatchKey
if curr_running
user_color_match(ix) = 1;
if realtime_feedback
if color_match_vec(ix)
set(h_txt_color,'Color',[0,1,0])
else
set(h_txt_color,'Color',[1,0,0])
end
end
end
case soundMatchKey
if curr_running
user_sound_match(ix) = 1;
if realtime_feedback
if sound_match_vec(ix)
set(h_txt_sound,'Color',[0,1,0])
else
set(h_txt_sound,'Color',[1,0,0])
end
end
end
case stopRunningKey
stop_running = 1;
otherwise
if curr_running
extraKeys{ix} = [extraKeys{ix}, ',', which_key.Key];
end
end
end
% Change nBack Types:
function change_types(~,~,which_type)
switch which_type
case 1,
switch position_on
case 1, set(types_menu(1),'Checked','off'); position_on = false;
set(h_txt_pos,'Visible','off')
case 0, set(types_menu(1),'Checked','on'); position_on = true;
set(h_txt_pos,'Visible','on')
end
case 2,
switch sound_on
case 1, set(types_menu(2),'Checked','off'); sound_on = false;
set(h_txt_sound,'Visible','off')
case 0, set(types_menu(2),'Checked','on'); sound_on = true;
set(h_txt_sound,'Visible','on')
end
case 3,
switch color_on
case 1, set(types_menu(3),'Checked','off'); color_on = false;
set(h_txt_color,'Visible','off')
set(handles.h_rect,'FaceColor','b')
case 0, set(types_menu(3),'Checked','on'); color_on = true;
set(h_txt_color,'Visible','on')
end
end
end
% Change nBack Level:
function change_nBack(~,~,nBack_spec)
nback = nBack_spec;
for ix1 = 1:20
set(h_nBack(ix1),'Checked','off');
end
set(h_nBack(nback),'Checked','on')
set(handles.figure,'name',['nback_matlab: (',num2str(nback),'-Back)'])
end
function change_lures(~,~,lure_spec)
percLure = poss_lures(lure_spec);
for ix1 = 1:21
set(h_lures(ix1),'Checked','off');
end
set(h_lures(lure_spec),'Checked','on')
end
% Change N Position Matches:
function change_position_matches(~,~,change_n)
n_positionHits = change_n;
for ixx = 1:n_poss
set(h_n_position_matches(ixx),'Checked','off');
end
set(h_n_position_matches(n_positionHits),'Checked','on')
end
% Change N Sound Matches:
function change_sound_matches(~,~,change_n)
n_soundHits = change_n;
for ixx = 1:n_poss
set(h_n_sound_matches(ixx),'Checked','off');
end
set(h_n_sound_matches(n_soundHits),'Checked','on')
end
% Change N Color Matches:
function change_color_matches(~,~,change_n)
n_colorHits = change_n;
for ixx = 1:n_poss
set(h_n_color_matches(ixx),'Checked','off');
end
set(h_n_color_matches(n_colorHits),'Checked','on')
end
% Change Completely Random:
function change_completely_random(hObject,~,~)
switch completely_random
case 1, set(hObject,'Checked','off'); completely_random = 0;
case 0, set(hObject,'Checked','on'); completely_random = 1;
end
end
% Change Advance Threshold:
function change_advance_thresh(~,~,advance_spec)
advance_thresh = advance_thresholds(advance_spec);
for ixx = 1:length(advance_thresholds)
set(h_advances(ixx),'Checked','off')
end
set(h_advances(advance_spec),'Checked','on')
end
% Change Advance Threshold:
function change_fallback_thresh(~,~,fallback_spec)
fallback_thresh = fallback_thresholds(fallback_spec);
for ixx = 1:length(fallback_thresholds)
set(h_fallbacks(ixx),'Checked','off')
end
set(h_fallbacks(fallback_spec),'Checked','on')
end
% Change # Trials:
function change_trial_num(~,~,trial_num_spec)
if (trial_num_spec > 1)
nTrials = trial_num_opts(trial_num_spec-1);
else
nTrials = nback + 20;
end
for ixx = 1:n_trial_num_opts+1
set(h_trial_num(ixx),'Checked','off')
end
set(h_trial_num(trial_num_spec),'Checked','on')
end
% Change Trial Time:
function change_trial_time(~,~,trial_time_spec)
trial_time = trial_time_opts(trial_time_spec);
for ixx = 1:n_trial_time_opts
set(h_trial_times(ixx),'Checked','off')
end
set(h_trial_times(trial_time_spec),'Checked','on')
end
% Change Show Remaining Trials:
function change_show_remaining(hObject,~,~)
switch show_remaining
case 1, set(hObject,'Checked','off'); show_remaining = 0;
case 0, set(hObject,'Checked','on'); show_remaining = 1;
end
end
function change_realtime_feedback(hObject,~,~)
switch realtime_feedback
case 1, set(hObject,'Checked','off'); realtime_feedback = 0;
case 0, set(hObject,'Checked','on'); realtime_feedback = 1;
end
end
function change_figure_feedback(hObject,~,~)
switch figure_window_feedback
case 1, set(hObject,'Checked','off'); figure_window_feedback = 0;
case 0, set(hObject,'Checked','on'); figure_window_feedback = 1;
end
end
function change_cmd_feedback(hObject,~,~)
switch command_line_feedback
case 1, set(hObject,'Checked','off'); command_line_feedback = 0;
case 0, set(hObject,'Checked','on'); command_line_feedback = 1;
end
end
% Change Sound Settings:
function change_volume(~,~,~)
if ~ishandle(h_volume)
h_volume = figure('menubar','none','color',background_color,'numbertitle',...
'off','name','Adjust Volume','units','norm','Position',[.4729,.8646,.2174,.0352]);
uicontrol(h_volume,'Style','slider','units','normalized','Position',...
[0,.2,1,.6],'Min',0,'Max',1.2,'Value',volume_factor,'Callback',@change_volume_slider);
else figure(h_volume)
end
end
function change_volume_slider(hObject,~,~)
volume_factor = hObject.Value;
end
function change_sound_types(~,~,which_type)
for ixx = 1:4; set(h_sound_types(ixx),'Checked','off'); end
set(h_sound_types(which_type),'Checked','on')
sound_type = which_type;
end
function change_applause_setting(hObject,~,~)
switch enable_applause
case 1, set(hObject,'Checked','off'); enable_applause = 0;
case 0, set(hObject,'Checked','on'); enable_applause = 1;
end
end
function change_boos_setting(hObject,~,~)
switch enable_boos
case 1, set(hObject,'Checked','off'); enable_boos = 0;
case 0, set(hObject,'Checked','on'); enable_boos = 1;
end
end
% Appearance:
function change_background(~,~,which_background)
switch which_background
case 1,
if strcmp(h_background_menu1.Checked,'on')
background_color_scheme = 2;
colors = {'y','m','c','r','g','b','k'};
set(h_background_menu1,'Checked','off')
set(h_background_menu2,'Checked','on')
elseif strcmp(h_background_menu1.Checked,'off')
background_color_scheme = 1;
colors = {'y','m','c','r','g','b','w'};
set(h_background_menu1,'Checked','on')
set(h_background_menu2,'Checked','off')
end
case 2,
if strcmp(h_background_menu2.Checked,'on')
background_color_scheme = 1;
colors = {'y','m','c','r','g','b','w'};
set(h_background_menu1,'Checked','on')
set(h_background_menu2,'Checked','off')
elseif strcmp(h_background_menu2.Checked,'off')
background_color_scheme = 2;
colors = {'y','m','c','r','g','b','k'};
set(h_background_menu1,'Checked','off')
set(h_background_menu2,'Checked','on')
end
end
if background_color_scheme==1
txt_color = ones(1,3);
set(handles.figure,'Color',zeros(1,3))
elseif background_color_scheme==2
txt_color = zeros(1,3);
set(handles.figure,'Color',ones(1,3))
end
for ixxx = 1:4
set(h_grid_lines(ixxx),'Color',txt_color)
end
set(h_title,'Color',txt_color); set(h_txt_begin,'Color',txt_color)
set(h_txt_pos,'Color',txt_color); set(h_txt_color,'Color',txt_color)
set(h_txt_sound,'Color',txt_color)
end
% Write Current Trial Data:
function writeData(pos_score, pos_lure_errors, H_pos, F_pos, ...
sound_score, sound_lure_errors, H_sound, F_sound, ...
color_score, color_lure_errors, H_color, F_color, trials, times, ...
position_matches, pos_lures, position_user, position_stimuli,...
sound_matches, sound_lures, sound_user, sound_stimuli, ...
color_matches, color_lures, color_user, color_stimuli, extraKeys)
if ~isdir(fullfile(script_path,'UserData')); mkdir(fullfile(script_path,'UserData')); end
dataPath = fullfile(script_path,'UserData','user_data.mat');
if exist(dataPath,'file')
load(dataPath);
summaryStats2 = table({char(datetime)}, nback, pos_score, ...
pos_lure_errors, H_pos, F_pos, sound_score, ...
sound_lure_errors, H_sound, F_sound, color_score, ...
color_lure_errors, H_color, F_color,'VariableNames',...
{'date_time','nback_level',...
'A_pos','lure_errors_pos','hits_pos','false_alarms_pos',...
'A_sound','lure_errors_sound','hits_sound','false_alarms_sound',...
'A_color','lure_errors_color','hits_color','false_alarms_color'});
summaryStats = [summaryStats; summaryStats2]; %#ok
trialData{length(trialData)+1} = table(trials, times, ...
position_matches,pos_lures, position_user, position_stimuli, ...
sound_matches, sound_lures, sound_user, sound_stimuli, ...
color_matches, color_lures, color_user, color_stimuli, extraKeys,...
'VariableNames',{'trial_num','seconds_from_start',...
'position_matches','position_lures','user_position_matches','position_stimuli',...
'sound_matches','sound_lures','user_sound_matches','sound_stimuli',...
'color_matches','color_lures','user_color_matches','color_stimuli','extra_keys'}); %#ok
else
summaryStats = table({char(datetime)}, nback, pos_score, ...
pos_lure_errors, H_pos, F_pos, sound_score, ...
sound_lure_errors, H_sound, F_sound, color_score, ...
color_lure_errors, H_color, F_color,'VariableNames',...
{'date_time','nback_level',...
'A_pos','lure_errors_pos','hits_pos','false_alarms_pos',...
'A_sound','lure_errors_sound','hits_sound','false_alarms_sound',...
'A_color','lure_errors_color','hits_color','false_alarms_color'}); %#ok
trialData{1} = table(trials, times, ...
position_matches,pos_lures, position_user, position_stimuli, ...
sound_matches, sound_lures, sound_user, sound_stimuli, ...
color_matches, color_lures, color_user, color_stimuli, extraKeys,...
'VariableNames',{'trial_num','seconds_from_start',...
'position_matches','position_lures','user_position_matches','position_stimuli',...
'sound_matches','sound_lures','user_sound_matches','sound_stimuli',...
'color_matches','color_lures','user_color_matches','color_stimuli','extra_keys'}); %#ok
end
save(dataPath,'summaryStats','trialData')
end
% Get Default Settings:
function get_defaults
nback = 2; % nBack level
percLure = .2; % proportion of non-match trials to become lures
nTrials = nback + 20;
trial_time = 2.4; % seconds
sound_on = true; % sound-type nBack: 1 (on), 0 (off)
position_on = true; % position-type nBack: 1 (on), 0 (off)
color_on = false; % color-type nBack: 1 (on), 0 (off)
completely_random = 0; % off (0), on (1) (if on, next 3 settings are irrelevant)
n_positionHits = 4; % control # of matches for position
n_soundHits = 4; % control # of matches for sound
n_colorHits = 4; % control # of matches for color
advance_thresh = .9; % A' default
fallback_thresh = .75; % A' default
volume_factor = 1; % Default: 1 (no change); >1 = increase volume; <1 = decrease volume
sound_type = 3; % use Numbers-Female (1), Numbers-Male (2), Letters-Female1 (3), or Letters-Female2 (4)
enable_applause = 1; % 1 (on) or 0 (off)
enable_boos = 0; % 1 (on) or 0 (off); comical boos if fail to advance to next nBack
realtime_feedback = 1; % 1 (on) or 0 (off); highlight labels red/green based on accuracy
figure_window_feedback = 1; % 1 (on) or 0 (off); display hits, misses, false alarms in figure window upon completion
command_line_feedback = 1; % 1 (on) or 0 (off); display hits, misses, false alarms in command window upon completion
show_remaining = 1; % 1 (on) or 0 (off); show remaining trials as title
background_color_scheme = 1; % black (1), white (2)
end
% Get Custom Settings:
function success = get_settings
if ~isdir(fullfile(script_path,'UserData')); mkdir(fullfile(script_path,'UserData')); end
listing = dir(fullfile(script_path,'UserData','nback_matlab_settings.txt'));
if isempty(listing);
success = 0;
get_defaults
return;
end
nback_matlab_settings = importdata(fullfile(script_path,'UserData',listing(1).name));
for ix1 = 1:length(customizable); eval(nback_matlab_settings{ix1}); end
success = 1;
end
% Write Custom Settings:
function write_settings
% Change Settings Data:
nback_matlab_settings = cell(length(customizable),1);
for ix1 = 1:length(customizable)
setting1 = eval(customizable{ix1});
nback_matlab_settings{ix1} = [customizable{ix1},'=',num2str(setting1),';'];
end
nback_matlab_settings = char(nback_matlab_settings);
% Write Text File:
if ~isdir(fullfile(script_path,'UserData')); mkdir(fullfile(script_path,'UserData')); end
fileID = fopen(fullfile(script_path,'UserData','nback_matlab_settings.txt'),'w');
for ix1 = 1:length(customizable)
fprintf(fileID,'%s\r\n',nback_matlab_settings(ix1,:));
end
fclose(fileID);
end
% Close Requests:
function close_nback_matlab(varargin)
% Save Custom Settings:
write_settings
% Close:
delete(handles.figure)
end
function enableMenus
set(handles.figure,'resize','on')
set(file_menu,'Enable','on'); set(session_menu,'Enable','on')
set(nBack_type_menu,'Enable','on'); set(feedback_menu,'Enable','on')
set(sound_settings_menu,'Enable','on'); set(appearance_menu,'Enable','on')
end
function disableMenus
clear sound % stop any sound if playing
set(handles.figure,'resize','off')
set(file_menu,'Enable','off')
set(session_menu,'Enable','off')
set(nBack_type_menu,'Enable','off')
set(feedback_menu,'Enable','off')
set(sound_settings_menu,'Enable','off')
set(appearance_menu,'Enable','off')
end
function resizeScreen(varargin)
if canResize
% Determine which dimension needs shrinking to become square:
for ixx = 1:4; set(h_grid_lines(ixx),'units','norm'); end
set(h_grid_lines(1),'Y',[minMeasure,maxMeasure])
set(h_grid_lines(2),'Y',[minMeasure,maxMeasure])