forked from KanoldLab/ToneBox
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathdataGraph.m
1413 lines (1218 loc) · 51.3 KB
/
dataGraph.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 varargout = dataGraph(varargin)
% Begin initialization code - DO NOT EDIT
gui_Singleton = 1;
gui_State = struct('gui_Name', mfilename, ...
'gui_Singleton', gui_Singleton, ...
'gui_OpeningFcn', @dataGraph_OpeningFcn, ...
'gui_OutputFcn', @dataGraph_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 dataGraph is made visible.
function dataGraph_OpeningFcn(hObject, eventdata, handles, varargin)
handles.output = hObject;
%sets file path to the current file that Matlab has open
fileLocation = pwd;
set(handles.fileLocation,'String',fileLocation);
%sets the defaults for all the buttons and text boxes
set(handles.checkDevices,'Enable','off')
set(handles.graphButton,'Enable','off')
set(handles.deviceChoice,'String','Device name','Enable','off')
set(handles.fileSelection,'Enable','off','String','Select File')
set(handles.waitStatus,'visible','off')
set(handles.runStatus,'visible','off')
set(handles.blockStatus,'visible','off')
set(handles.failStatus,'visible','off')
%creates large vector of all the buttons that correspond to the different
%devices
handles.checkPiButtons = [handles.check1;handles.check2;handles.check3;...
handles.check4;handles.check5;handles.check6;handles.check7;...
handles.check8;handles.check9;handles.check10;handles.check11;...
handles.check12;handles.check13;handles.check14;handles.check15;...
handles.check16];
%setting variable to be used in the email notification function
handles.statusLoop = 0;
guidata(hObject, handles);
function varargout = dataGraph_OutputFcn(hObject, eventdata, handles)
varargout{1} = handles.output;
function deviceChoice_Callback(hObject, eventdata, handles)
handles.fileChoice = [];
% data location is given a variable
handles.dataLocation = [handles.devicesFolder,handles.deviceChoice.String,'/'];
% checks to see if the entered string is a valid device name by searching
% for the device folder
checkLocation = exist(handles.dataLocation);
if checkLocation == 0
% pop up message box if the device name is invalid
popup = msgbox('Invalid device name');
else
%lists all the performance files in chronological order
handles.listFolder = dir(handles.dataLocation);
validFiles = find(~[handles.listFolder.isdir]);
fileDates = [handles.listFolder.datenum];
[~,sortedFiles] = sort(fileDates,'descend');
sortedFiles = sortedFiles(ismember(sortedFiles,validFiles));
textDisplay = {};
for z = 1:numel(sortedFiles)
if handles.listFolder(sortedFiles(z)).name(2) == 'e'
textDisplay = [textDisplay;{handles.listFolder(sortedFiles(z)).name}];
end
end
handles.fileSelection.String = textDisplay;
%enables file selection and graph button
set(handles.fileSelection,'Enable','on')
set(handles.graphButton,'Enable','on')
end
guidata(hObject, handles);
function deviceChoice_CreateFcn(hObject, eventdata, handles)
if ispc && isequal(get(hObject,'BackgroundColor'), get(0,'defaultUicontrolBackgroundColor'))
set(hObject,'BackgroundColor','white');
end
function graphButton_Callback(hObject, eventdata, handles)
%if no file is selected, the most recent file is selected for graphing
if isempty(handles.fileChoice)
handles.fileChoice = 1;
end
% loads the file, catch loop is in case the selected file is being saved
% simultaneously, the loop catch will pause and try to load again
try
load([handles.dataLocation,handles.fileSelection.String{handles.fileChoice}])
catch
pause(1)
load([handles.dataLocation,handles.fileSelection.String{handles.fileChoice}])
end
set(handles.fileSelection,'Value',handles.fileChoice)
% displays the trial that just finished for the associated
% device in the correct tab
set(handles.trialDisplay,'String',['Total Trials = ', num2str(totalTrials)]);
%displays the time at which the last trial was recorded
try
set(handles.trialRecordText,'String',['Last Trial Recorded: ',timeStamp{length(timeStamp),2}])
catch
set(handles.trialRecordText,'String','Last Trial Recorded: waiting for more data')
end
% if the phase selected was discrimination, targets vs
% nontargets are graphed
if phaseChoice == 4
% the text box for target tones displays which ones were
% selected for the associated device in the correct tab
set(handles.targetDisplay,'String',['Target Tones:',{target}]);
% the text box for nontarget tones displays which ones were
% selected for the associated device in the correct tab
set(handles.nontargetDisplay,'String',['Nontarget Tones:', {nontarget}]);
% displays the phase selected
set(handles.phaseDisplay,'String',['Phase:',{'Discrimination'}]);
% sets the graph's parent to be in the correct panel/tab
subplot(2,2,1,'Parent',handles.graphPanel);
% plots response latency, aka first lick, blue line is for
% licks on target trials, red line is for licks on
% nontarget trials, axes are set for x axis to be from 0 to
% 4 seconds, and y axis set from 0 to 1 for relative
% response over total trials
plot(xaxis,(lickResponseTarget/totalTrials),'b',xaxis,...
(lickResponseNonTarget/totalTrials),'r')
xlabel('Time(s)')
ylabel('Percentage')
xlim([0 4])
% sets the graph's parent to be in the correct panel/tab
subplot(2,2,2,'Parent',handles.graphPanel);
% histogram of response types
histogram('Categories',{'hit','false alarm','early'},'BinCounts',...
[(hitCount/totalTrials); (falseAlarmCount/totalTrials); (earlyCount/totalTrials)])
ylim([0 1])
ylabel('Response Rate')
xlabel('Response')
% sets the graph's parent to be in the correct panel/tab
subplot(2,2,[3,4],'Parent',handles.graphPanel);
% plots average lick response, blue line is
% for target trials, red line is for nontarget trials
plot(xaxis,mean(totalDataTarget),'b',xaxis,mean(totalDataNonTarget),'r')
xlabel('Time(s)')
ylabel('Lick Rate')
xlim([0 4])
% red box around target response zone
aa=axis;
x1 = [1 1];
y1 = [0 aa(4)]*.5;
x2 = [1 3];
y2 = [aa(4) aa(4)]*.5;
x3 = [3 3];
line(x1,y1,'Color','r','LineStyle','--')
line(x2,y2,'Color','r','LineStyle','--')
line(x3,y1,'Color','r','LineStyle','--')
end
% if habituation is selected
if phaseChoice == 1
% the text box for target tones displays which ones were
% selected for the associated device in the correct tab
set(handles.targetDisplay,'String',['Target Tones:',{'none'}]);
% the text box for nontarget tones displays which ones were
% selected for the associated device in the correct tab
set(handles.nontargetDisplay,'String',['Nontarget Tones:',{'none'}]);
% displays the phase selected
set(handles.phaseDisplay,'String',['Phase:',{'Habituation'}]);
% sets the graph's parent to be in the correct panel/tab
subplot(2,2,1,'Parent',handles.graphPanel);
% plots response latency, aka first lick, axes are set
% for x axis to be from 0 to 10 seconds, and y axis set
% from 0 to 1 for relative response over total trials
plot(xaxis,(lickResponse/totalTrials));
xlabel('Time(s)')
ylabel('Percentage')
xlim([0 10]);
% sets the graph's parent to be in the correct panel/tab
subplot(2,2,2,'Parent',handles.graphPanel);
% percentage of hits
plot((hitCount/totalTrials),'bs')
xlim([0 2])
ylim([0 1])
set(gca,'XTick',[])
ylabel('Response Rate')
xlabel('Hit Response')
% sets the graph's parent to be in the correct panel/tab
subplot(2,2,[3,4],'Parent',handles.graphPanel);
% plots average lick response
plot(xaxis,mean(totalData));
xlabel('Time(s)')
ylabel('Lick Rate')
xlim([0 10])
end
% if shaping is selected
if phaseChoice == 2
set(handles.phaseDisplay,'String',['Phase',{'Shaping'}]);
%clear plots
delete(handles.graphPanel.Children(2:end))
% the text box for target tones displays which ones were
% selected for the associated device in the correct tab
set(handles.targetDisplay,'String',['Target Tones:', {target}]);
% the text box for nontarget tones displays which ones were
% selected for the associated device in the correct tab
set(handles.nontargetDisplay,'String',['Nontarget Tones:',{'none'}]);
%%%%% Trialwise Data %%%%%
subplot(2,3,1:2,'Parent',handles.graphPanel);
cla
%Hits
H=zeros(length(responseVec),1);
%Conditioned Hits
C=zeros(length(responseVec),1);
%Early
E=zeros(length(responseVec),1);
for i = 1:length(responseVec)
if strcmpi(responseVec(i),'H')
H(i)=1;
elseif strcmpi(responseVec(i),'C')
C(i)=1;
elseif strcmpi(responseVec(i),'E')
E(i)=1;
end
end
plot(100*movmean(cumsum(H)./[1:length(H)]',100),'b','linewidth',2);
hold on
plot(100*movmean(cumsum(C)./[1:length(C)]',100),'color',[0 .5 .5],'linewidth',2);
plot(100*movmean(cumsum(E)./[1:length(E)]',100),'k','linewidth',2);
xlim([1 length(responseVec)])
aa=axis;
ylim([aa(3) aa(4)+5])
h=legend('H_R','H_C','E','autoupdate','off');
legend boxoff
xlabel('Trials')
ylabel('Response Rate (%)')
set(gca,'fontsize',8)
title('Trialwise Responses')
%Select trials
if ~isempty(handles.AnalysisTrials.String)
T = str2num(handles.AnalysisTrials.String);
if length(T) == 1
T = [1 T];
end
T=sort(T);
if max(T) > length(H)
T(end) = length(H);
end
if T(1) < 1
T(1) = 1;
end
handles.AnalysisTrials.String = num2str(T);
aa=axis;
area(T,repmat(aa(4)*.5,[1 length(T)]),'edgecolor','none','facecolor','k','facealpha',.2)
text(mean(T),(aa(4)*.5)+.75,'Analysis trials','fontsize',7,'HorizontalAlignment','center')
toneVec = toneVec(T(1):T(2));
responseVec = responseVec(T(1):T(2));
%Recalculate lickResponse, H, C, and E for selected trials
nbins = size(totalData,2);
lickResponse = zeros(1,nbins);
firstLick=[];
for i = T(1):T(2)
firstLick=find(totalData(i,:)>0,1);
lickResponse(1,firstLick) = lickResponse(1,firstLick) + 1;
firstLick=[];
end
%Hits
hitCount=zeros(length(responseVec),1);
%Conditioned Hits
condHitCount=zeros(length(responseVec),1);
%Early
earlyCount=zeros(length(responseVec),1);
for i = 1:length(responseVec)
if strcmpi(responseVec(i),'H')
hitCount(i)=1;
elseif strcmpi(responseVec(i),'C')
condHitCount(i)=1;
elseif strcmpi(responseVec(i),'E')
earlyCount(i)=1;
end
end
hitCount=sum(hitCount);
condHitCount=sum(condHitCount);
earlyCount=sum(earlyCount);
totalTrials = length(responseVec);
end
%Spectrum
try
subplot(2,3,3,'Parent',handles.graphPanel);
cla
F = unique(toneVec)';
Hf=[];
for i = 1:length(F)
f = find(toneVec==F(i));
Hf(i)=sum(responseVec(f)=='H')./length(f);
end
plot(1:length(F),100*Hf,'k');
hold on
plot(1:length(F),100*Hf,'ks','markerface','k')
set(gca,'xtick',1:length(F),'xticklabel',F)
xlabel('Frequency (kHz)')
set(gca,'fontsize',8)
title([{'Tone Responses'}])
aa=axis;
ylim([0 aa(4)])
end
% sets the graph's parent to be in the correct panel/tab
subplot(2,3,4,'Parent',handles.graphPanel);
cla
% plots response latency, aka first lick, axes are set
% for x axis to be from 0 to 4 seconds, and y axis set
% from 0 to 1 for relative response over total trials
L = lickResponse/sum(lickResponse);
LL = smooth(L,10);
area(xaxis,100*LL,'facecolor','b','facealpha',.5,'edgecolor','none');
aa=axis;
ylim([aa(3) aa(4)+5])
h=legend('T','AutoUpdate','off');
legend boxoff
xlabel('Time(s)')
ylabel('Likelihood (%)')
xlim([0 4]);
hold on
title('Response Latency')
set(gca,'fontsize',8)
% box around target
aa=axis;
x1 = [1 1];
y1 = [0 aa(4)]*.5;
x2 = [1 2];
y2 = [aa(4) aa(4)]*.5;
x3 = [2 2];
line(x1,y1,'Color','k','LineStyle','-','linewidth',2)
line(x2,y2,'Color','k','LineStyle','-','linewidth',2)
line(x3,y1,'Color','k','LineStyle','-','linewidth',2)
% sets the graph's parent to be in the correct panel/tab
subplot(2,3,6,'Parent',handles.graphPanel);
cla
% histogram of response types from animal
bar(1,100*hitCount/totalTrials,'facecolor','b','edgecolor','none');
hold on
bar(2,100*condHitCount/totalTrials,'facecolor',[0 .5 .5],'edgecolor','none');
bar(3,100*earlyCount/totalTrials,'facecolor','none','edgecolor','k');
set(gca,'xtick',1:3,'xticklabel',{'H_R','H_C','E'})
title('Response Rates')
set(gca,'fontsize',8)
% sets the graph's parent to be in the correct panel/tab
subplot(2,3,5,'Parent',handles.graphPanel);
cla
% plots average lick response
L = mean(totalData);
LL = smooth(L,10);
area(xaxis,100*LL,'facecolor','b','facealpha',.5,'edgecolor','none');
xlabel('Time(s)')
xlim([0 4]);
hold on
title('Lick-o-gram')
set(gca,'fontsize',8)
aa=axis;
ylim([aa(3) aa(4)])
% box around target
aa=axis;
x1 = [1 1];
y1 = [0 aa(4)]*.5;
x2 = [1 2];
y2 = [aa(4) aa(4)]*.5;
x3 = [2 2];
line(x1,y1,'Color','k','LineStyle','-','linewidth',2)
line(x2,y2,'Color','k','LineStyle','-','linewidth',2)
line(x3,y1,'Color','k','LineStyle','-','linewidth',2)
end
if phaseChoice == 3
set(handles.phaseDisplay,'String',['Phase:',{'Detection'}]);
%clear plots
delete(handles.graphPanel.Children(2:end))
% the text box for target tones displays which ones were
% selected for the associated device in the correct tab
set(handles.targetDisplay,'String',['Target Tones:', {target}]);
% the text box for nontarget tones displays which ones were
% selected for the associated device in the correct tab
set(handles.nontargetDisplay,'String',['Nontarget Tones:',{'none'}]);
%%%%% Trialwise Data %%%%%
subplot(2,3,1:2,'Parent',handles.graphPanel);
cla
%Hits
H=zeros(length(responseVec),1);
%Early
E=zeros(length(responseVec),1);
for i = 1:length(responseVec)
if strcmpi(responseVec(i),'H')
H(i)=1;
elseif strcmpi(responseVec(i),'E')
E(i)=1;
end
end
plot(100*movmean(H,100),'b','linewidth',2);
hold on
plot(100*movmean(E,100),'k','linewidth',2);
xlim([1 length(responseVec)])
aa=axis;
ylim([aa(3) aa(4)+5])
h=legend('H_R','E','autoupdate','off');
legend boxoff
xlabel('Trials')
ylabel('Response Rate (%)')
set(gca,'fontsize',8)
title('Trialwise Responses')
%Select trials
if ~isempty(handles.AnalysisTrials.String)
T = str2num(handles.AnalysisTrials.String);
if length(T) == 1
T = [1 T];
end
T=sort(T);
if max(T) > length(H)
T(end) = length(H);
end
if T(1) < 1
T(1) = 1;
end
handles.AnalysisTrials.String = num2str(T);
aa=axis;
area(T,repmat(aa(4)*.5,[1 length(T)]),'edgecolor','none','facecolor','k','facealpha',.2)
text(mean(T),(aa(4)*.5)+.75,'Analysis trials','fontsize',7,'HorizontalAlignment','center')
toneVec = toneVec(T(1):T(2));
responseVec = responseVec(T(1):T(2));
totalData = totalData(T(1):T(2),:);
%Recalculate lickResponse, H, and E for selected trials
nbins = size(totalData,2);
lickResponse = zeros(1,nbins);
firstLick=[];
for i = 1:size(totalData,1);
firstLick=find(totalData(i,:)>0,1);
lickResponse(1,firstLick) = lickResponse(1,firstLick) + 1;
firstLick=[];
end
%Hits
hitCount=zeros(length(responseVec),1);
%Eary=ly
earlyCount=zeros(length(responseVec),1);
for i = 1:length(responseVec)
if strcmpi(responseVec(i),'H')
hitCount(i)=1;
elseif strcmpi(responseVec(i),'E')
earlyCount(i)=1;
end
end
hitCount=sum(hitCount);
earlyCount=sum(earlyCount);
totalTrials = length(responseVec);
end
%Spectrum
try
subplot(2,3,3,'Parent',handles.graphPanel);
cla
F = unique(toneVec)';
Hf=[];
for i = 1:length(F)
f = find(toneVec==F(i));
Hf(i)=sum(responseVec(f)=='H')./length(f);
end
plot(1:length(F),100*Hf,'k');
hold on
plot(1:length(F),100*Hf,'ks','markerface','k')
set(gca,'xtick',1:length(F),'xticklabel',F)
xlabel('Frequency (kHz)')
set(gca,'fontsize',8)
title([{'Tone Responses'}])
aa=axis;
ylim([0 aa(4)])
end
% sets the graph's parent to be in the correct panel/tab
subplot(2,3,4,'Parent',handles.graphPanel);
cla
% plots response latency, aka first lick, axes are set
% for x axis to be from 0 to 4 seconds, and y axis set
% from 0 to 1 for relative response over total trials
L = lickResponse/sum(lickResponse);
LL = smooth(L,10);
area(xaxis,100*LL,'facecolor','b','facealpha',.5,'edgecolor','none');
aa=axis;
ylim([aa(3) aa(4)+5])
h=legend('T','AutoUpdate','off');
legend boxoff
xlabel('Time(s)')
ylabel('Likelihood (%)')
xlim([0 4]);
hold on
title('Response Latency')
set(gca,'fontsize',8)
% box around target
aa=axis;
x1 = [1 1];
y1 = [0 aa(4)]*.5;
x2 = [1 2];
y2 = [aa(4) aa(4)]*.5;
x3 = [2 2];
line(x1,y1,'Color','k','LineStyle','-','linewidth',2)
line(x2,y2,'Color','k','LineStyle','-','linewidth',2)
line(x3,y1,'Color','k','LineStyle','-','linewidth',2)
% sets the graph's parent to be in the correct panel/tab
subplot(2,3,6,'Parent',handles.graphPanel);
cla
% histogram of response types from animal
bar(1,100*hitCount/totalTrials,'facecolor','b','edgecolor','none');
hold on
bar(2,100*earlyCount/totalTrials,'facecolor','none','edgecolor','k');
set(gca,'xtick',1:3,'xticklabel',{'H_R','E'})
title('Response Rates')
set(gca,'fontsize',8)
% sets the graph's parent to be in the correct panel/tab
subplot(2,3,5,'Parent',handles.graphPanel);
cla
% plots average lick response
L = mean(totalData);
LL = smooth(L,10);
area(xaxis,100*LL,'facecolor','b','facealpha',.5,'edgecolor','none');
xlabel('Time(s)')
xlim([0 4]);
hold on
title('Lick-o-gram')
set(gca,'fontsize',8)
aa=axis;
ylim([aa(3) aa(4)])
% box around target
aa=axis;
x1 = [1 1];
y1 = [0 aa(4)]*.5;
x2 = [1 2];
y2 = [aa(4) aa(4)]*.5;
x3 = [2 2];
line(x1,y1,'Color','k','LineStyle','-','linewidth',2)
line(x2,y2,'Color','k','LineStyle','-','linewidth',2)
line(x3,y1,'Color','k','LineStyle','-','linewidth',2)
end
% immediately plots data
drawnow;
guidata(hObject, handles);
function fileSelection_Callback(hObject, eventdata, handles)
handles.fileChoice = get(hObject,'Value');
guidata(hObject, handles);
function fileSelection_CreateFcn(hObject, eventdata, handles)
if ispc && isequal(get(hObject,'BackgroundColor'), get(0,'defaultUicontrolBackgroundColor'))
set(hObject,'BackgroundColor','white');
end
%checks status of the devices that are currently running on button press
function checkDevices_Callback(hObject, eventdata, handles)
handles.failCheck = 0;
%loads file that has a list of all the running devices
load([handles.devicesFolder 'currentDevices.mat'])
if numel(onDevices) > 0
set(handles.emailNotif,'Enable','on')
end
%for each device it first checks that the parameters have been moved into
%the associated folder and then looks at when the most recent trial was
%saved and then color codes the device based on the status
for z = 1:numel(onDevices)
set(handles.checkPiButtons(z),'Enable','on')
loaded = 0;
while ~loaded
try
load([handles.devicesFolder onDevices{z} '/performance.mat'])
load([handles.devicesFolder onDevices{z} '/stopButton.mat'])
loaded = 1;
end
end
set(handles.checkPiButtons(z),'String',onDevices{z})
try
t1 = clock;
t2 = datevec(timeStamp{length(timeStamp),2});
timeCheck = (etime(t1,t2))/60;
%if the device is not on an inter block interval and has recorded a
%trial within the last 10 minutes then the status is green
if timeCheck < 10 && blockInterval == 0 && pauseProgram == 0
set(handles.checkPiButtons(z),'BackgroundColor','g','ForegroundColor','k')
%if the device is not on an inter block interval and hasn't recorded a
%trial within the last 10 minutes then the status is red
elseif timeCheck > 2 && blockInterval == 0 && pauseProgram == 0
set(handles.checkPiButtons(z),'BackgroundColor','r','ForegroundColor','k')
%if the device is on an inter block interval and has recorded a
%trial within the last 70 minutes then the status is yellow
elseif timeCheck < 70 && blockInterval == 1 && pauseProgram == 0
set(handles.checkPiButtons(z),'BackgroundColor','y','ForegroundColor','k')
%if the device is on an inter block interval and hasn't recorded a
%trial within the last 70 minutes then the status is red
elseif timeCheck > 70 && blockInterval == 1 && pauseProgram == 0
set(handles.checkPiButtons(z),'BackgroundColor','r','ForegroundColor','k')
%if the device has been paused then the status is magenta
elseif pauseProgram == 1
set(handles.checkPiButtons(z),'BackgroundColor','m','ForegroundColor','w')
end
catch
%if the parameters file has not been moved to the associated
%device folder then the status is blue
set(handles.checkPiButtons(z),'BackgroundColor','b','ForegroundColor','w')
end
end
%names the buttons to the corresponding device name
for z = numel(onDevices) + 1:16
set(handles.checkPiButtons(z),'BackgroundColor','default','ForegroundColor','k')
set(handles.checkPiButtons(z),'String',['Pi',num2str(z)])
end
%legend
set(handles.waitStatus,'visible','on')
set(handles.runStatus,'visible','on')
set(handles.blockStatus,'visible','on')
set(handles.failStatus,'visible','on')
set(handles.pauseStatus,'visible','on')
guidata(hObject, handles);
%graphs data from most recent/current file for the device by populating the
%information into the file selection drop down menus and running the graph
%function
function check1_Callback(hObject, eventdata, handles)
if length(handles.check1.String) > 4
delete(handles.graphPanel.Children(2:end))
set(handles.deviceChoice,'String',handles.check1.String)
handles.fileChoice = [];
set(handles.trialDisplay,'String','');
set(handles.trialRecordText,'String','')
set(handles.AnalysisTrials,'String','')
% data location is given a variable
handles.dataLocation = [handles.devicesFolder,handles.deviceChoice.String,'/'];
handles.listFolder = dir(handles.dataLocation);
validFiles = find(~[handles.listFolder.isdir]);
fileDates = [handles.listFolder.datenum];
[~,sortedFiles] = sort(fileDates,'descend');
sortedFiles = sortedFiles(ismember(sortedFiles,validFiles));
textDisplay = {};
for z = 1:numel(sortedFiles)
if handles.listFolder(sortedFiles(z)).name(2) == 'e'
textDisplay = [textDisplay;{handles.listFolder(sortedFiles(z)).name}];
end
end
handles.fileSelection.String = textDisplay;
set(handles.fileSelection,'Enable','on')
set(handles.graphButton,'Enable','on')
graphButton_Callback(hObject, eventdata, handles)
end
guidata(hObject, handles);
%graphs data from most recent/current file for the device by populating the
%information into the file selection drop down menus and running the graph
%function
function check2_Callback(hObject, eventdata, handles)
if length(handles.check2.String) > 4
set(handles.deviceChoice,'String',handles.check2.String)
handles.fileChoice = [];
delete(handles.graphPanel.Children(2:end))
set(handles.trialDisplay,'String','');
set(handles.trialRecordText,'String','')
set(handles.AnalysisTrials,'String','')
% data location is given a variable
handles.dataLocation = [handles.devicesFolder,handles.deviceChoice.String,'/'];
handles.listFolder = dir(handles.dataLocation);
validFiles = find(~[handles.listFolder.isdir]);
fileDates = [handles.listFolder.datenum];
[~,sortedFiles] = sort(fileDates,'descend');
sortedFiles = sortedFiles(ismember(sortedFiles,validFiles));
textDisplay = {};
for z = 1:numel(sortedFiles)
if handles.listFolder(sortedFiles(z)).name(2) == 'e'
textDisplay = [textDisplay;{handles.listFolder(sortedFiles(z)).name}];
end
end
handles.fileSelection.String = textDisplay;
set(handles.fileSelection,'Enable','on')
set(handles.graphButton,'Enable','on')
graphButton_Callback(hObject, eventdata, handles)
end
guidata(hObject, handles);
%graphs data from most recent/current file for the device by populating the
%information into the file selection drop down menus and running the graph
%function
function check3_Callback(hObject, eventdata, handles)
if length(handles.check3.String) > 4
set(handles.deviceChoice,'String',handles.check3.String)
handles.fileChoice = [];
delete(handles.graphPanel.Children(2:end))
set(handles.trialDisplay,'String','');
set(handles.trialRecordText,'String','')
set(handles.AnalysisTrials,'String','')
% data location is given a variable
handles.dataLocation = [handles.devicesFolder,handles.deviceChoice.String,'/'];
handles.listFolder = dir(handles.dataLocation);
validFiles = find(~[handles.listFolder.isdir]);
fileDates = [handles.listFolder.datenum];
[~,sortedFiles] = sort(fileDates,'descend');
sortedFiles = sortedFiles(ismember(sortedFiles,validFiles));
textDisplay = {};
for z = 1:numel(sortedFiles)
if handles.listFolder(sortedFiles(z)).name(2) == 'e'
textDisplay = [textDisplay;{handles.listFolder(sortedFiles(z)).name}];
end
end
handles.fileSelection.String = textDisplay;
set(handles.fileSelection,'Enable','on')
set(handles.graphButton,'Enable','on')
graphButton_Callback(hObject, eventdata, handles)
end
guidata(hObject, handles);
%graphs data from most recent/current file for the device by populating the
%information into the file selection drop down menus and running the graph
%function
function check4_Callback(hObject, eventdata, handles)
if length(handles.check4.String) > 4
set(handles.deviceChoice,'String',handles.check4.String)
handles.fileChoice = [];
delete(handles.graphPanel.Children(2:end))
set(handles.trialDisplay,'String','');
set(handles.trialRecordText,'String','')
set(handles.AnalysisTrials,'String','')
% data location is given a variable
handles.dataLocation = [handles.devicesFolder,handles.deviceChoice.String,'/'];
handles.listFolder = dir(handles.dataLocation);
validFiles = find(~[handles.listFolder.isdir]);
fileDates = [handles.listFolder.datenum];
[~,sortedFiles] = sort(fileDates,'descend');
sortedFiles = sortedFiles(ismember(sortedFiles,validFiles));
textDisplay = {};
for z = 1:numel(sortedFiles)
if handles.listFolder(sortedFiles(z)).name(2) == 'e'
textDisplay = [textDisplay;{handles.listFolder(sortedFiles(z)).name}];
end
end
handles.fileSelection.String = textDisplay;
set(handles.fileSelection,'Enable','on')
set(handles.graphButton,'Enable','on')
graphButton_Callback(hObject, eventdata, handles)
end
guidata(hObject, handles);
%graphs data from most recent/current file for the device by populating the
%information into the file selection drop down menus and running the graph
%function
function check5_Callback(hObject, eventdata, handles)
if length(handles.check5.String) > 4
set(handles.deviceChoice,'String',handles.check5.String)
handles.fileChoice = [];
delete(handles.graphPanel.Children(2:end))
set(handles.trialDisplay,'String','');
set(handles.trialRecordText,'String','')
set(handles.AnalysisTrials,'String','')
% data location is given a variable
handles.dataLocation = [handles.devicesFolder,handles.deviceChoice.String,'/'];
handles.listFolder = dir(handles.dataLocation);
validFiles = find(~[handles.listFolder.isdir]);
fileDates = [handles.listFolder.datenum];
[~,sortedFiles] = sort(fileDates,'descend');
sortedFiles = sortedFiles(ismember(sortedFiles,validFiles));
textDisplay = {};
for z = 1:numel(sortedFiles)
if handles.listFolder(sortedFiles(z)).name(2) == 'e'
textDisplay = [textDisplay;{handles.listFolder(sortedFiles(z)).name}];
end
end
handles.fileSelection.String = textDisplay;
set(handles.fileSelection,'Enable','on')
set(handles.graphButton,'Enable','on')
graphButton_Callback(hObject, eventdata, handles)
end
guidata(hObject, handles);
%graphs data from most recent/current file for the device by populating the
%information into the file selection drop down menus and running the graph
%function
function check6_Callback(hObject, eventdata, handles)
if length(handles.check6.String) > 4
set(handles.deviceChoice,'String',handles.check6.String)
handles.fileChoice = [];
delete(handles.graphPanel.Children(2:end))
set(handles.trialDisplay,'String','');
set(handles.trialRecordText,'String','')
set(handles.AnalysisTrials,'String','')
% data location is given a variable
handles.dataLocation = [handles.devicesFolder,handles.deviceChoice.String,'/'];
handles.listFolder = dir(handles.dataLocation);
validFiles = find(~[handles.listFolder.isdir]);
fileDates = [handles.listFolder.datenum];
[~,sortedFiles] = sort(fileDates,'descend');
sortedFiles = sortedFiles(ismember(sortedFiles,validFiles));
textDisplay = {};
for z = 1:numel(sortedFiles)
if handles.listFolder(sortedFiles(z)).name(2) == 'e'
textDisplay = [textDisplay;{handles.listFolder(sortedFiles(z)).name}];
end
end
handles.fileSelection.String = textDisplay;
set(handles.fileSelection,'Enable','on')
set(handles.graphButton,'Enable','on')
graphButton_Callback(hObject, eventdata, handles)
end
guidata(hObject, handles);
%graphs data from most recent/current file for the device by populating the
%information into the file selection drop down menus and running the graph
%function
function check7_Callback(hObject, eventdata, handles)
if length(handles.check7.String) > 4
set(handles.deviceChoice,'String',handles.check7.String)
handles.fileChoice = [];
delete(handles.graphPanel.Children(2:end))
set(handles.trialDisplay,'String','');
set(handles.trialRecordText,'String','')
set(handles.AnalysisTrials,'String','')
% data location is given a variable
handles.dataLocation = [handles.devicesFolder,handles.deviceChoice.String,'/'];
handles.listFolder = dir(handles.dataLocation);
validFiles = find(~[handles.listFolder.isdir]);
fileDates = [handles.listFolder.datenum];
[~,sortedFiles] = sort(fileDates,'descend');
sortedFiles = sortedFiles(ismember(sortedFiles,validFiles));
textDisplay = {};
for z = 1:numel(sortedFiles)
if handles.listFolder(sortedFiles(z)).name(2) == 'e'
textDisplay = [textDisplay;{handles.listFolder(sortedFiles(z)).name}];
end
end
handles.fileSelection.String = textDisplay;
set(handles.fileSelection,'Enable','on')
set(handles.graphButton,'Enable','on')
graphButton_Callback(hObject, eventdata, handles)
end
guidata(hObject, handles);
%graphs data from most recent/current file for the device by populating the
%information into the file selection drop down menus and running the graph
%function
function check8_Callback(hObject, eventdata, handles)
if length(handles.check8.String) > 4
set(handles.deviceChoice,'String',handles.check8.String)
handles.fileChoice = [];
delete(handles.graphPanel.Children(2:end))
set(handles.trialDisplay,'String','');
set(handles.trialRecordText,'String','')
set(handles.AnalysisTrials,'String','')
% data location is given a variable
handles.dataLocation = [handles.devicesFolder,handles.deviceChoice.String,'/'];
handles.listFolder = dir(handles.dataLocation);
validFiles = find(~[handles.listFolder.isdir]);
fileDates = [handles.listFolder.datenum];
[~,sortedFiles] = sort(fileDates,'descend');
sortedFiles = sortedFiles(ismember(sortedFiles,validFiles));
textDisplay = {};
for z = 1:numel(sortedFiles)
if handles.listFolder(sortedFiles(z)).name(2) == 'e'
textDisplay = [textDisplay;{handles.listFolder(sortedFiles(z)).name}];
end
end
handles.fileSelection.String = textDisplay;
set(handles.fileSelection,'Enable','on')
set(handles.graphButton,'Enable','on')
graphButton_Callback(hObject, eventdata, handles)
end
guidata(hObject, handles);
%graphs data from most recent/current file for the device by populating the
%information into the file selection drop down menus and running the graph
%function
function check9_Callback(hObject, eventdata, handles)
if length(handles.check9.String) > 4
set(handles.deviceChoice,'String',handles.check9.String)
handles.fileChoice = [];
delete(handles.graphPanel.Children(2:end))
set(handles.trialDisplay,'String','');
set(handles.trialRecordText,'String','')
set(handles.AnalysisTrials,'String','')
% data location is given a variable
handles.dataLocation = [handles.devicesFolder,handles.deviceChoice.String,'/'];
handles.listFolder = dir(handles.dataLocation);
validFiles = find(~[handles.listFolder.isdir]);
fileDates = [handles.listFolder.datenum];
[~,sortedFiles] = sort(fileDates,'descend');
sortedFiles = sortedFiles(ismember(sortedFiles,validFiles));