-
Notifications
You must be signed in to change notification settings - Fork 0
/
behavior_count.m
1006 lines (793 loc) · 38.4 KB
/
behavior_count.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 = behavior_count(varargin)
% BEHAVIOR_COUNT M-file for behavior_count.fig
% BEHAVIOR_COUNT, by itself, creates a new BEHAVIOR_COUNT or raises the existing
% singleton*.
%
% H = BEHAVIOR_COUNT returns the handle to a new BEHAVIOR_COUNT or the handle to
% the existing singleton*.
%
% BEHAVIOR_COUNT('CALLBACK',hObject,eventData,handles,...) calls the local
% function named CALLBACK in BEHAVIOR_COUNT.M with the given input arguments.
%
% BEHAVIOR_COUNT('Property','Value',...) creates a new BEHAVIOR_COUNT or raises the
% existing singleton*. Starting from the left, property value pairs are
% applied to the GUI before behavior_count_OpeningFcn gets called. An
% unrecognized property name or invalid value makes property application
% stop. All inputs are passed to behavior_count_OpeningFcn via varargin.
%
% *See GUI Options on GUIDE's Tools menu. Choose "GUI allows only one
% instance to run (singleton)".
%
% See also: GUIDE, GUIDATA, GUIHANDLES
% Edit the above text to modify the response to help behavior_count
% Last Modified by GUIDE v2.5 12-May-2015 11:30:46
% Begin initialization code - DO NOT EDIT
gui_Singleton = 1;
gui_State = struct('gui_Name', mfilename, ...
'gui_Singleton', gui_Singleton, ...
'gui_OpeningFcn', @behavior_count_OpeningFcn, ...
'gui_OutputFcn', @behavior_count_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 behavior_count is made visible.
function behavior_count_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 behavior_count (see VARARGIN)
% Choose default command line output for behavior_count
handles.output = hObject;
% Update handles structure
guidata(hObject, handles);
% UIWAIT makes behavior_count wait for user response (see UIRESUME)
% uiwait(handles.figure1);
% --- Outputs from this function are returned to the command line.
function varargout = behavior_count_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;
% --- Executes on button press in pushbuttonEating.
function pushbuttonEating_Callback(hObject, eventdata, handles)
% hObject handle to pushbuttonEating (see GCBO)
% eventdata reserved - to be defined in a future version of MATLAB
% handles structure with handles and user data (see GUIDATA)
Start = length(get(handles.pushbuttonStart,'Visible'));%判断Start是否按下,按下为off,3,没按为on,2.
if Start == 2
display('Press Start button fist!');
return;
end
EatingTime = get(handles.editEatingTime,'string');
EatingTime = str2num(EatingTime);
EatingNum = get(handles.editEatingNum,'string');
EatingNum = str2num(EatingNum);
tocA = 0; tocB = 0; TimePlot = [0 0];
E_color = get(handles.pushbuttonEating,'BackgroundColor');
if E_color == [1 1 0]
tocA = toc;
if tocA > handles.MovieDuration %判断是否超出movie长度
return;
end
set(handles.pushbuttonEating,'BackgroundColor',[1 0 0 ]);
handles.tocA = tocA;
TimePlot = [tocA 1];
handles.Eating = [handles.Eating;TimePlot];
elseif E_color == [1 0 0 ]
tocB = toc;
if tocB > handles.MovieDuration %判断是否超出movie长度
tocB = handles.MovieDuration;
end
set(handles.pushbuttonEating,'BackgroundColor',[1 1 0 ]);
EatingNum = EatingNum +1;
EatingTime = EatingTime + tocB - handles.tocA;
set(handles.editEatingTime,'string',num2str(EatingTime));
set(handles.editEatingNum,'string',num2str(EatingNum));
TimePlot = [tocB 0];
handles.Eating = [handles.Eating;TimePlot];
end
%set(handles.axesEating,'UserData',stairs(handles.Eating(:,1),handles.Eating(:,2)));
stairs(handles.axesEating,handles.Eating(:,1),handles.Eating(:,2));
set(handles.axesEating,'YLim',[0 2]);
set(handles.axesEating,'xLim',[0 handles.MovieDuration]);
hold on;
guidata(hObject, handles);
% --- If Enable == 'on', executes on mouse press in 5 pixel border.
% --- Otherwise, executes on mouse press in 5 pixel border or over pushbuttonEating.
function pushbuttonEating_ButtonDownFcn(hObject, eventdata, handles)
% hObject handle to pushbuttonEating (see GCBO)
% eventdata reserved - to be defined in a future version of MATLAB
% handles structure with handles and user data (see GUIDATA)
% --- Executes on button press in pushbuttonDrinking.
function pushbuttonDrinking_Callback(hObject, eventdata, handles)
% hObject handle to pushbuttonDrinking (see GCBO)
% eventdata reserved - to be defined in a future version of MATLAB
% handles structure with handles and user data (see GUIDATA)
Start = length(get(handles.pushbuttonStart,'Visible'));%判断Start是否按下,按下为off,3,没按为on,2.
if Start == 2
display('Press Start button fist!');
return;
end
DrinkingTime = get(handles.editDrinkingTime,'string');
DrinkingTime = str2num(DrinkingTime);
DrinkingNum = str2num(get(handles.editDrinkingNum,'string'));
tocA = 0; tocB = 0; TimePlot = [0 0];
E_color = get(handles.pushbuttonDrinking,'BackgroundColor');
if E_color == [1 1 0]
tocA = toc;
if tocA > handles.MovieDuration
return;
end
set(handles.pushbuttonDrinking,'BackgroundColor',[1 0 0 ]);
handles.tocA = tocA;
TimePlot = [tocA 1];
handles.Drinking = [handles.Drinking;TimePlot];
elseif E_color == [1 0 0 ]
tocB = toc;
if tocB > handles.MovieDuration
tocB = handles.MovieDuration;
end
set(handles.pushbuttonDrinking,'BackgroundColor',[1 1 0 ]);
DrinkingNum = DrinkingNum +1;
DrinkingTime = DrinkingTime + tocB - handles.tocA;
set(handles.editDrinkingTime,'string',num2str(DrinkingTime));
set(handles.editDrinkingNum,'string',num2str(DrinkingNum));
TimePlot = [tocB 0];
handles.Drinking = [handles.Drinking;TimePlot];
end
stairs(handles.axesDrinking,handles.Drinking(:,1),handles.Drinking(:,2));
set(handles.axesDrinking,'YLim',[0 2]);
set(handles.axesDrinking,'xLim',[0 handles.MovieDuration]);
hold on;
guidata(hObject, handles);
% --- Executes on key press with focus on figure1 and none of its controls.
function figure1_KeyPressFcn(hObject, eventdata, handles)
% hObject handle to figure1 (see GCBO)
% eventdata structure with the following fields (see FIGURE)
% Key: name of the key that was pressed, in lower case
% Character: character interpretation of the key(s) that was pressed
% Modifier: name(s) of the modifier key(s) (i.e., control, shift) pressed
% handles structure with handles and user data (see GUIDATA)
function editEatingTime_Callback(hObject, eventdata, handles)
% hObject handle to editEatingTime (see GCBO)
% eventdata reserved - to be defined in a future version of MATLAB
% handles structure with handles and user data (see GUIDATA)
% Hints: get(hObject,'String') returns contents of editEatingTime as text
% str2double(get(hObject,'String')) returns contents of editEatingTime as a double
% --- Executes during object creation, after setting all properties.
function editEatingTime_CreateFcn(hObject, eventdata, handles)
% hObject handle to editEatingTime (see GCBO)
% eventdata reserved - to be defined in a future version of MATLAB
% handles empty - handles not created until after all CreateFcns called
% Hint: edit controls usually have a white background on Windows.
% See ISPC and COMPUTER.
if ispc && isequal(get(hObject,'BackgroundColor'), get(0,'defaultUicontrolBackgroundColor'))
set(hObject,'BackgroundColor','white');
end
function editEatingNum_Callback(hObject, eventdata, handles)
% hObject handle to editEatingNum (see GCBO)
% eventdata reserved - to be defined in a future version of MATLAB
% handles structure with handles and user data (see GUIDATA)
% Hints: get(hObject,'String') returns contents of editEatingNum as text
% str2double(get(hObject,'String')) returns contents of editEatingNum as a double
% --- Executes during object creation, after setting all properties.
function editEatingNum_CreateFcn(hObject, eventdata, handles)
% hObject handle to editEatingNum (see GCBO)
% eventdata reserved - to be defined in a future version of MATLAB
% handles empty - handles not created until after all CreateFcns called
% Hint: edit controls usually have a white background on Windows.
% See ISPC and COMPUTER.
if ispc && isequal(get(hObject,'BackgroundColor'), get(0,'defaultUicontrolBackgroundColor'))
set(hObject,'BackgroundColor','white');
end
% --- Executes on button press in pushbuttonStart.
function pushbuttonStart_Callback(hObject, eventdata, handles)
% hObject handle to pushbuttonStart (see GCBO)
% eventdata reserved - to be defined in a future version of MATLAB
% handles structure with handles and user data (see GUIDATA)
tic;
clc;
set(handles.pushbuttonStop,'Visible','on');
set(handles.pushbuttonStart,'Visible','off');
%所有变量归0,清空。
set(handles.editEatingTime,'string','0');
set(handles.editEatingNum,'string','0');
cla(handles.axesEating);
handles.Eating = [0 0];
set(handles.pushbuttonEating,'BackgroundColor',[1 1 0 ]);
set(handles.editDrinkingTime,'string','0');
set(handles.editDrinkingNum,'string','0');
cla(handles.axesDrinking);
handles.Drinking = [0 0];
set(handles.pushbuttonDrinking,'BackgroundColor',[1 1 0 ]);
set(handles.editDiggingTime,'string','0');
set(handles.editDiggingNum,'string','0');
cla(handles.axesDigging);
handles.Digging = [0 0];
set(handles.pushbuttonDigging,'BackgroundColor',[1 1 0 ]);
set(handles.editWalkingTime,'string','0');
set(handles.editWalkingNum,'string','0');
cla(handles.axesWalking);
handles.Walking = [0 0];
set(handles.pushbuttonWalking,'BackgroundColor',[1 1 0 ]);
set(handles.editJumpingTime,'string','0');
set(handles.editJumpingNum,'string','0');
cla(handles.axesJumping);
handles.Jumping = [0 0];
set(handles.pushbuttonJumping,'BackgroundColor',[1 1 0 ]);
set(handles.editRearingTime,'string','0');
set(handles.editRearingNum,'string','0');
cla(handles.axesRearing);
handles.Rearing = [0 0];
set(handles.pushbuttonRearing,'BackgroundColor',[1 1 0 ]);
% handles.MovieDuration = str2num(get(handles.editMovieDuration,'string')) * 60;
handles.MovieDuration = str2num(get(handles.editMovieDuration,'string'));
handles.tocA = 0;
guidata(hObject, handles);
function editDrinkingTime_Callback(hObject, eventdata, handles)
% hObject handle to editDrinkingTime (see GCBO)
% eventdata reserved - to be defined in a future version of MATLAB
% handles structure with handles and user data (see GUIDATA)
% Hints: get(hObject,'String') returns contents of editDrinkingTime as text
% str2double(get(hObject,'String')) returns contents of editDrinkingTime as a double
% --- Executes during object creation, after setting all properties.
function editDrinkingTime_CreateFcn(hObject, eventdata, handles)
% hObject handle to editDrinkingTime (see GCBO)
% eventdata reserved - to be defined in a future version of MATLAB
% handles empty - handles not created until after all CreateFcns called
% Hint: edit controls usually have a white background on Windows.
% See ISPC and COMPUTER.
if ispc && isequal(get(hObject,'BackgroundColor'), get(0,'defaultUicontrolBackgroundColor'))
set(hObject,'BackgroundColor','white');
end
function editDrinkingNum_Callback(hObject, eventdata, handles)
% hObject handle to editDrinkingNum (see GCBO)
% eventdata reserved - to be defined in a future version of MATLAB
% handles structure with handles and user data (see GUIDATA)
% Hints: get(hObject,'String') returns contents of editDrinkingNum as text
% str2double(get(hObject,'String')) returns contents of editDrinkingNum as a double
% --- Executes during object creation, after setting all properties.
function editDrinkingNum_CreateFcn(hObject, eventdata, handles)
% hObject handle to editDrinkingNum (see GCBO)
% eventdata reserved - to be defined in a future version of MATLAB
% handles empty - handles not created until after all CreateFcns called
% Hint: edit controls usually have a white background on Windows.
% See ISPC and COMPUTER.
if ispc && isequal(get(hObject,'BackgroundColor'), get(0,'defaultUicontrolBackgroundColor'))
set(hObject,'BackgroundColor','white');
end
% --- Executes on button press in pushbuttonStop.
function pushbuttonStop_Callback(hObject, eventdata, handles)
% hObject handle to pushbuttonStop (see GCBO)
% eventdata reserved - to be defined in a future version of MATLAB
% handles structure with handles and user data (see GUIDATA)
set(handles.pushbuttonStart,'Visible','on');
set(handles.pushbuttonStop,'Visible','off');
AnalysisData.Eating = handles.Eating;
AnalysisData.Drinking = handles.Drinking;
AnalysisData.Digging = handles.Digging;
AnalysisData.Walking = handles.Walking;
AnalysisData.Jumping = handles.Jumping;
AnalysisData.Rearing = handles.Rearing;
EatingTime = str2num(get(handles.editEatingTime,'string'));
EatingNum = str2num(get(handles.editEatingNum,'string'));
AnalysisData.TimeNum = [EatingTime EatingNum];
DrinkingTime = str2num(get(handles.editDrinkingTime,'string'));
DrinkingNum = str2num(get(handles.editDrinkingNum,'string'));
TimeNum = [DrinkingTime DrinkingNum];
AnalysisData.TimeNum = [AnalysisData.TimeNum;TimeNum];
DiggingTime = str2num(get(handles.editDiggingTime,'string'));
DiggingNum = str2num(get(handles.editDiggingNum,'string'));
TimeNum = [DiggingTime DiggingNum];
AnalysisData.TimeNum = [AnalysisData.TimeNum;TimeNum];
WalkingTime = str2num(get(handles.editWalkingTime,'string'));
WalkingNum = str2num(get(handles.editWalkingNum,'string'));
TimeNum = [WalkingTime WalkingNum];
AnalysisData.TimeNum = [AnalysisData.TimeNum;TimeNum];
JumpingTime = str2num(get(handles.editJumpingTime,'string'));
JumpingNum = str2num(get(handles.editJumpingNum,'string'));
TimeNum = [JumpingTime JumpingNum];
AnalysisData.TimeNum = [AnalysisData.TimeNum;TimeNum];
RearingTime = str2num(get(handles.editRearingTime,'string'));
RearingNum = str2num(get(handles.editRearingNum,'string'));
TimeNum = [RearingTime RearingNum];
AnalysisData.TimeNum = [AnalysisData.TimeNum;TimeNum];
handles.AnalysisData = AnalysisData;
% [filename filepath index] = uiputfile('*.mat');
% if index
% str = [filepath filename];
% save(str,'AnalysisData');
% else
% save AnalysisData AnalysisData;
% end
guidata(hObject, handles);
% clear all;
function edit5_Callback(hObject, eventdata, handles)
% hObject handle to edit5 (see GCBO)
% eventdata reserved - to be defined in a future version of MATLAB
% handles structure with handles and user data (see GUIDATA)
% Hints: get(hObject,'String') returns contents of edit5 as text
% str2double(get(hObject,'String')) returns contents of edit5 as a double
% --- Executes during object creation, after setting all properties.
function edit5_CreateFcn(hObject, eventdata, handles)
% hObject handle to edit5 (see GCBO)
% eventdata reserved - to be defined in a future version of MATLAB
% handles empty - handles not created until after all CreateFcns called
% Hint: edit controls usually have a white background on Windows.
% See ISPC and COMPUTER.
if ispc && isequal(get(hObject,'BackgroundColor'), get(0,'defaultUicontrolBackgroundColor'))
set(hObject,'BackgroundColor','white');
end
% --- Executes on button press in pushbuttonDigging.
function pushbuttonDigging_Callback(hObject, eventdata, handles)
% hObject handle to pushbuttonDigging (see GCBO)
% eventdata reserved - to be defined in a future version of MATLAB
% handles structure with handles and user data (see GUIDATA)
Start = length(get(handles.pushbuttonStart,'Visible'));%判断Start是否按下,按下为off,3,没按为on,2.
if Start == 2
display('Press Start button fist!');
return;
end
DiggingTime = get(handles.editDiggingTime,'string');
DiggingTime = str2num(DiggingTime);
DiggingNum = get(handles.editDiggingNum,'string');
DiggingNum = str2num(DiggingNum);
tocA = 0; tocB = 0; TimePlot = [0 0];
E_color = get(handles.pushbuttonDigging,'BackgroundColor');
if E_color == [1 1 0]
tocA = toc;
if tocA > handles.MovieDuration
return;
end
set(handles.pushbuttonDigging,'BackgroundColor',[1 0 0 ]);
handles.tocA = tocA;
TimePlot = [tocA 1];
handles.Digging = [handles.Digging;TimePlot];
elseif E_color == [1 0 0 ]
tocB = toc;
if tocB > handles.MovieDuration
tocB = handles.MovieDuration;
end
set(handles.pushbuttonDigging,'BackgroundColor',[1 1 0 ]);
DiggingNum = DiggingNum +1;
DiggingTime = DiggingTime + tocB - handles.tocA;
set(handles.editDiggingTime,'string',num2str(DiggingTime));
set(handles.editDiggingNum,'string',num2str(DiggingNum));
TimePlot = [tocB 0];
handles.Digging = [handles.Digging;TimePlot];
end
stairs(handles.axesDigging,handles.Digging(:,1),handles.Digging(:,2));
set(handles.axesDigging,'YLim',[0 2]);
set(handles.axesDigging,'xLim',[0 handles.MovieDuration]);
hold on;
guidata(hObject, handles);
function editDiggingTime_Callback(hObject, eventdata, handles)
% hObject handle to editDiggingTime (see GCBO)
% eventdata reserved - to be defined in a future version of MATLAB
% handles structure with handles and user data (see GUIDATA)
% Hints: get(hObject,'String') returns contents of editDiggingTime as text
% str2double(get(hObject,'String')) returns contents of editDiggingTime as a double
% --- Executes during object creation, after setting all properties.
function editDiggingTime_CreateFcn(hObject, eventdata, handles)
% hObject handle to editDiggingTime (see GCBO)
% eventdata reserved - to be defined in a future version of MATLAB
% handles empty - handles not created until after all CreateFcns called
% Hint: edit controls usually have a white background on Windows.
% See ISPC and COMPUTER.
if ispc && isequal(get(hObject,'BackgroundColor'), get(0,'defaultUicontrolBackgroundColor'))
set(hObject,'BackgroundColor','white');
end
function editDiggingNum_Callback(hObject, eventdata, handles)
% hObject handle to editDiggingNum (see GCBO)
% eventdata reserved - to be defined in a future version of MATLAB
% handles structure with handles and user data (see GUIDATA)
% Hints: get(hObject,'String') returns contents of editDiggingNum as text
% str2double(get(hObject,'String')) returns contents of editDiggingNum as a double
% --- Executes during object creation, after setting all properties.
function editDiggingNum_CreateFcn(hObject, eventdata, handles)
% hObject handle to editDiggingNum (see GCBO)
% eventdata reserved - to be defined in a future version of MATLAB
% handles empty - handles not created until after all CreateFcns called
% Hint: edit controls usually have a white background on Windows.
% See ISPC and COMPUTER.
if ispc && isequal(get(hObject,'BackgroundColor'), get(0,'defaultUicontrolBackgroundColor'))
set(hObject,'BackgroundColor','white');
end
% --- Executes on button press in pushbuttonWalking.
function pushbuttonWalking_Callback(hObject, eventdata, handles)
% hObject handle to pushbuttonWalking (see GCBO)
% eventdata reserved - to be defined in a future version of MATLAB
% handles structure with handles and user data (see GUIDATA)
Start = length(get(handles.pushbuttonStart,'Visible'));%判断Start是否按下,按下为off,3,没按为on,2.
if Start == 2
display('Press Start button fist!');
return;
end
WalkingTime = get(handles.editWalkingTime,'string');
WalkingTime = str2num(WalkingTime);
WalkingNum = get(handles.editWalkingNum,'string');
WalkingNum = str2num(WalkingNum);
tocA = 0; tocB = 0; TimePlot = [0 0];
E_color = get(handles.pushbuttonWalking,'BackgroundColor');
if E_color == [1 1 0]
tocA = toc;
if tocA > handles.MovieDuration
return;
end
set(handles.pushbuttonWalking,'BackgroundColor',[1 0 0 ]);
handles.tocA = tocA;
TimePlot = [tocA 1];
handles.Walking = [handles.Walking;TimePlot];
elseif E_color == [1 0 0 ]
tocB = toc;
if tocB > handles.MovieDuration
tocB = handles.MovieDuration;
end
set(handles.pushbuttonWalking,'BackgroundColor',[1 1 0 ]);
WalkingNum = WalkingNum +1;
WalkingTime = WalkingTime + tocB - handles.tocA;
set(handles.editWalkingTime,'string',num2str(WalkingTime));
set(handles.editWalkingNum,'string',num2str(WalkingNum));
TimePlot = [tocB 0];
handles.Walking = [handles.Walking;TimePlot];
end
stairs(handles.axesWalking,handles.Walking(:,1),handles.Walking(:,2));
set(handles.axesWalking,'YLim',[0 2]);
set(handles.axesWalking,'xLim',[0 handles.MovieDuration]);
hold on;
guidata(hObject, handles);
function editWalkingTime_Callback(hObject, eventdata, handles)
% hObject handle to editWalkingTime (see GCBO)
% eventdata reserved - to be defined in a future version of MATLAB
% handles structure with handles and user data (see GUIDATA)
% Hints: get(hObject,'String') returns contents of editWalkingTime as text
% str2double(get(hObject,'String')) returns contents of editWalkingTime as a double
% --- Executes during object creation, after setting all properties.
function editWalkingTime_CreateFcn(hObject, eventdata, handles)
% hObject handle to editWalkingTime (see GCBO)
% eventdata reserved - to be defined in a future version of MATLAB
% handles empty - handles not created until after all CreateFcns called
% Hint: edit controls usually have a white background on Windows.
% See ISPC and COMPUTER.
if ispc && isequal(get(hObject,'BackgroundColor'), get(0,'defaultUicontrolBackgroundColor'))
set(hObject,'BackgroundColor','white');
end
function editWalkingNum_Callback(hObject, eventdata, handles)
% hObject handle to editWalkingNum (see GCBO)
% eventdata reserved - to be defined in a future version of MATLAB
% handles structure with handles and user data (see GUIDATA)
% Hints: get(hObject,'String') returns contents of editWalkingNum as text
% str2double(get(hObject,'String')) returns contents of editWalkingNum as a double
% --- Executes during object creation, after setting all properties.
function editWalkingNum_CreateFcn(hObject, eventdata, handles)
% hObject handle to editWalkingNum (see GCBO)
% eventdata reserved - to be defined in a future version of MATLAB
% handles empty - handles not created until after all CreateFcns called
% Hint: edit controls usually have a white background on Windows.
% See ISPC and COMPUTER.
if ispc && isequal(get(hObject,'BackgroundColor'), get(0,'defaultUicontrolBackgroundColor'))
set(hObject,'BackgroundColor','white');
end
% --- Executes on button press in pushbuttonJumping.
function pushbuttonJumping_Callback(hObject, eventdata, handles)
% hObject handle to pushbuttonJumping (see GCBO)
% eventdata reserved - to be defined in a future version of MATLAB
% handles structure with handles and user data (see GUIDATA)
Start = length(get(handles.pushbuttonStart,'Visible'));%判断Start是否按下,按下为off,3,没按为on,2.
if Start == 2
display('Press Start button fist!');
return;
end
JumpingTime = get(handles.editJumpingTime,'string');
JumpingTime = str2num(JumpingTime);
JumpingNum = get(handles.editJumpingNum,'string');
JumpingNum = str2num(JumpingNum);
tocA = 0; tocB = 0; TimePlot = [0 0];
E_color = get(handles.pushbuttonJumping,'BackgroundColor');
if E_color == [1 1 0]
tocA = toc;
if tocA > handles.MovieDuration
return;
end
set(handles.pushbuttonJumping,'BackgroundColor',[1 0 0 ]);
handles.tocA = tocA;
TimePlot = [tocA 1];
handles.Jumping = [handles.Jumping;TimePlot];
elseif E_color == [1 0 0 ]
tocB = toc;
if tocB > handles.MovieDuration
tocB = handles.MovieDuration;
end
set(handles.pushbuttonJumping,'BackgroundColor',[1 1 0 ]);
JumpingNum = JumpingNum +1;
JumpingTime = JumpingTime + tocB - handles.tocA;
set(handles.editJumpingTime,'string',num2str(JumpingTime));
set(handles.editJumpingNum,'string',num2str(JumpingNum));
TimePlot = [tocB 0];
handles.Jumping = [handles.Jumping;TimePlot];
end
stairs(handles.axesJumping,handles.Jumping(:,1),handles.Jumping(:,2));
set(handles.axesJumping,'YLim',[0 2]);
set(handles.axesJumping,'xLim',[0 handles.MovieDuration]);
hold on;
guidata(hObject, handles);
function editJumpingTime_Callback(hObject, eventdata, handles)
% hObject handle to editJumpingTime (see GCBO)
% eventdata reserved - to be defined in a future version of MATLAB
% handles structure with handles and user data (see GUIDATA)
% Hints: get(hObject,'String') returns contents of editJumpingTime as text
% str2double(get(hObject,'String')) returns contents of editJumpingTime as a double
% --- Executes during object creation, after setting all properties.
function editJumpingTime_CreateFcn(hObject, eventdata, handles)
% hObject handle to editJumpingTime (see GCBO)
% eventdata reserved - to be defined in a future version of MATLAB
% handles empty - handles not created until after all CreateFcns called
% Hint: edit controls usually have a white background on Windows.
% See ISPC and COMPUTER.
if ispc && isequal(get(hObject,'BackgroundColor'), get(0,'defaultUicontrolBackgroundColor'))
set(hObject,'BackgroundColor','white');
end
function editJumpingNum_Callback(hObject, eventdata, handles)
% hObject handle to editJumpingNum (see GCBO)
% eventdata reserved - to be defined in a future version of MATLAB
% handles structure with handles and user data (see GUIDATA)
% Hints: get(hObject,'String') returns contents of editJumpingNum as text
% str2double(get(hObject,'String')) returns contents of editJumpingNum as a double
% --- Executes during object creation, after setting all properties.
function editJumpingNum_CreateFcn(hObject, eventdata, handles)
% hObject handle to editJumpingNum (see GCBO)
% eventdata reserved - to be defined in a future version of MATLAB
% handles empty - handles not created until after all CreateFcns called
% Hint: edit controls usually have a white background on Windows.
% See ISPC and COMPUTER.
if ispc && isequal(get(hObject,'BackgroundColor'), get(0,'defaultUicontrolBackgroundColor'))
set(hObject,'BackgroundColor','white');
end
% --- Executes on button press in pushbuttonRearing.
function pushbuttonRearing_Callback(hObject, eventdata, handles)
% hObject handle to pushbuttonRearing (see GCBO)
% eventdata reserved - to be defined in a future version of MATLAB
% handles structure with handles and user data (see GUIDATA)
Start = length(get(handles.pushbuttonStart,'Visible'));%判断Start是否按下,按下为off,3,没按为on,2.
if Start == 2
display('Press Start button fist!');
return;
end
RearingTime = get(handles.editRearingTime,'string');
RearingTime = str2num(RearingTime);
RearingNum = get(handles.editRearingNum,'string');
RearingNum = str2num(RearingNum);
tocA = 0; tocB = 0; TimePlot = [0 0];
E_color = get(handles.pushbuttonRearing,'BackgroundColor');
if E_color == [1 1 0] %判断是否超出movie长度
tocA = toc;
if tocA > handles.MovieDuration
return;
end
set(handles.pushbuttonRearing,'BackgroundColor',[1 0 0 ]);
handles.tocA = tocA;
TimePlot = [tocA 1];
handles.Rearing = [handles.Rearing;TimePlot];
elseif E_color == [1 0 0 ]
tocB = toc;
if tocB > handles.MovieDuration
tocB = handles.MovieDuration;
end
set(handles.pushbuttonRearing,'BackgroundColor',[1 1 0 ]);
RearingNum = RearingNum +1;
RearingTime = RearingTime + tocB - handles.tocA;
set(handles.editRearingTime,'string',num2str(RearingTime));
set(handles.editRearingNum,'string',num2str(RearingNum));
TimePlot = [tocB 0];
handles.Rearing = [handles.Rearing;TimePlot];
end
stairs(handles.axesRearing,handles.Rearing(:,1),handles.Rearing(:,2));
set(handles.axesRearing,'YLim',[0 2]);
set(handles.axesRearing,'xLim',[0 handles.MovieDuration]);
hold on;
guidata(hObject, handles);
function editRearingTime_Callback(hObject, eventdata, handles)
% hObject handle to editRearingTime (see GCBO)
% eventdata reserved - to be defined in a future version of MATLAB
% handles structure with handles and user data (see GUIDATA)
% Hints: get(hObject,'String') returns contents of editRearingTime as text
% str2double(get(hObject,'String')) returns contents of editRearingTime as a double
% --- Executes during object creation, after setting all properties.
function editRearingTime_CreateFcn(hObject, eventdata, handles)
% hObject handle to editRearingTime (see GCBO)
% eventdata reserved - to be defined in a future version of MATLAB
% handles empty - handles not created until after all CreateFcns called
% Hint: edit controls usually have a white background on Windows.
% See ISPC and COMPUTER.
if ispc && isequal(get(hObject,'BackgroundColor'), get(0,'defaultUicontrolBackgroundColor'))
set(hObject,'BackgroundColor','white');
end
function editRearingNum_Callback(hObject, eventdata, handles)
% hObject handle to editRearingNum (see GCBO)
% eventdata reserved - to be defined in a future version of MATLAB
% handles structure with handles and user data (see GUIDATA)
% Hints: get(hObject,'String') returns contents of editRearingNum as text
% str2double(get(hObject,'String')) returns contents of editRearingNum as a double
% --- Executes during object creation, after setting all properties.
function editRearingNum_CreateFcn(hObject, eventdata, handles)
% hObject handle to editRearingNum (see GCBO)
% eventdata reserved - to be defined in a future version of MATLAB
% handles empty - handles not created until after all CreateFcns called
% Hint: edit controls usually have a white background on Windows.
% See ISPC and COMPUTER.
if ispc && isequal(get(hObject,'BackgroundColor'), get(0,'defaultUicontrolBackgroundColor'))
set(hObject,'BackgroundColor','white');
end
function editMovieDuration_Callback(hObject, eventdata, handles)
% hObject handle to editMovieDuration (see GCBO)
% eventdata reserved - to be defined in a future version of MATLAB
% handles structure with handles and user data (see GUIDATA)
% Hints: get(hObject,'String') returns contents of editMovieDuration as text
% str2double(get(hObject,'String')) returns contents of editMovieDuration as a double
% --- Executes during object creation, after setting all properties.
function editMovieDuration_CreateFcn(hObject, eventdata, handles)
% hObject handle to editMovieDuration (see GCBO)
% eventdata reserved - to be defined in a future version of MATLAB
% handles empty - handles not created until after all CreateFcns called
% Hint: edit controls usually have a white background on Windows.
% See ISPC and COMPUTER.
if ispc && isequal(get(hObject,'BackgroundColor'), get(0,'defaultUicontrolBackgroundColor'))
set(hObject,'BackgroundColor','white');
end
% --- Executes on key press with focus on figure1 or any of its controls.
function figure1_WindowKeyPressFcn(hObject, eventdata, handles)
% hObject handle to figure1 (see GCBO)
% eventdata structure with the following fields (see FIGURE)
% Key: name of the key that was pressed, in lower case
% Character: character interpretation of the key(s) that was pressed
% Modifier: name(s) of the modifier key(s) (i.e., control, shift) pressed
% handles structure with handles and user data (see GUIDATA)
key_input = eventdata.Key;
if length(key_input)>1 %如果不是字母或数字键,(空格,回车,ctrl,shift等),结束这个函数;
return;
end
if key_input == 'E'||key_input == 'e'
pushbuttonEating_Callback(hObject, eventdata, handles);
elseif key_input == 'D'||key_input == 'd'
pushbuttonDrinking_Callback(hObject, eventdata, handles);
elseif key_input == 'G'||key_input == 'g'
pushbuttonDigging_Callback(hObject, eventdata, handles);
elseif key_input == 'W'||key_input == 'w'
pushbuttonWalking_Callback(hObject, eventdata, handles);
elseif key_input == 'J'||key_input == 'j'
pushbuttonJumping_Callback(hObject, eventdata, handles);
elseif key_input == 'R'||key_input == 'r'
pushbuttonRearing_Callback(hObject, eventdata, handles);
else
return;
end
function edit_behaviorThreshold_Callback(hObject, eventdata, handles)
% hObject handle to edit_behaviorThreshold (see GCBO)
% eventdata reserved - to be defined in a future version of MATLAB
% handles structure with handles and user data (see GUIDATA)
% Hints: get(hObject,'String') returns contents of edit_behaviorThreshold as text
% str2double(get(hObject,'String')) returns contents of edit_behaviorThreshold as a double
% --- Executes during object creation, after setting all properties.
function edit_behaviorThreshold_CreateFcn(hObject, eventdata, handles)
% hObject handle to edit_behaviorThreshold (see GCBO)
% eventdata reserved - to be defined in a future version of MATLAB
% handles empty - handles not created until after all CreateFcns called
% Hint: edit controls usually have a white background on Windows.
% See ISPC and COMPUTER.
if ispc && isequal(get(hObject,'BackgroundColor'), get(0,'defaultUicontrolBackgroundColor'))
set(hObject,'BackgroundColor','white');
end
% --- Executes on button press in pushbutton_FilterSection.
function pushbutton_FilterSection_Callback(hObject, eventdata, handles)
% hObject handle to pushbutton_FilterSection (see GCBO)
% eventdata reserved - to be defined in a future version of MATLAB
% handles structure with handles and user data (see GUIDATA)
pushbuttonStop_Callback(hObject, eventdata, handles)
guidata(hObject, handles);
AnalysisData = handles.AnalysisData;
behaviorThreshold = str2num(get(handles.edit_behaviorThreshold,'string'));
sectionDuration = str2num(get(handles.edit_sectionDuration,'string'));
MovieDuration = str2num(get(handles.editMovieDuration,'string'));
data = AnalysisData.Drinking;
if size(data,1)>2%判断有behavior出现
%%%%%%%%%%%filt data
behaviorDuration = data(3:2:end,1)-data(2:2:end-1,1);
index = find(behaviorDuration>=behaviorThreshold);
data_filt = zeros(size(data))-1;
data_filt(index*2,:) = data(index*2,:);
data_filt(index*2+1,:) = data(index*2+1,:);
index = find(data_filt(:,1)==-1);
data_filt(index,:) = [];
% figure;
% d = [0,0;data_filt];
% stairs(d(:,1),d(:,2));
% set(gca,'YLim',[0 2]);
% set(gca,'xLim',[0 handles.MovieDuration]);
%%%%%%%%%%%section data
sectionNum = round(MovieDuration/sectionDuration);
for i = 1:sectionNum
n = max(find(data_filt(:,1)<=sectionDuration*i));
n = n + mod(n,2); %奇数转成大1的偶数,behavior在section时间点上发生
dataT = data_filt(1:n,1);
if dataT(n)>sectionDuration*i
dataT(n) = sectionDuration*i;
end
data_cumulate(i) = sum(dataT(2:2:n)-dataT(1:2:n-1)); %累积behavior
end
data_section(1) = data_cumulate(1);
data_section(2:sectionNum) = diff(data_cumulate);
data_section(sectionNum+1) = data_cumulate(sectionNum);% total behavior
data_section = data_section';
data_section = round(data_section*100)/100;%保留2位小数
assignin('base','data_section',data_section);
else
display('No behavior');
end
function edit_sectionDuration_Callback(hObject, eventdata, handles)
% hObject handle to edit_sectionDuration (see GCBO)
% eventdata reserved - to be defined in a future version of MATLAB
% handles structure with handles and user data (see GUIDATA)
% Hints: get(hObject,'String') returns contents of edit_sectionDuration as text
% str2double(get(hObject,'String')) returns contents of edit_sectionDuration as a double
% --- Executes during object creation, after setting all properties.
function edit_sectionDuration_CreateFcn(hObject, eventdata, handles)
% hObject handle to edit_sectionDuration (see GCBO)
% eventdata reserved - to be defined in a future version of MATLAB
% handles empty - handles not created until after all CreateFcns called
% Hint: edit controls usually have a white background on Windows.
% See ISPC and COMPUTER.
if ispc && isequal(get(hObject,'BackgroundColor'), get(0,'defaultUicontrolBackgroundColor'))
set(hObject,'BackgroundColor','white');
end
% --- Executes during object creation, after setting all properties.
function pushbutton_FilterSection_CreateFcn(hObject, eventdata, handles)
% hObject handle to pushbutton_FilterSection (see GCBO)
% eventdata reserved - to be defined in a future version of MATLAB
% handles empty - handles not created until after all CreateFcns called
% --- Executes on button press in pushbutton13.
function pushbutton13_Callback(hObject, eventdata, handles)
% hObject handle to pushbutton13 (see GCBO)
% eventdata reserved - to be defined in a future version of MATLAB
% handles structure with handles and user data (see GUIDATA)
if isfield(handles,'pathname')
path = [handles.pathname '*.mat'];
[filename,pathname,index] = uigetfile(path);
else
[filename,pathname,index] = uigetfile('*.mat');
end
if index
str = [pathname filename];
handles.pathname = pathname;
handles.AnalysisData = importdata(str);
set(handles.edit_fileName,'string',filename);
else
set(handles.edit_fileName,'string','Null');
end
guidata(hObject, handles);
function edit_fileName_Callback(hObject, eventdata, handles)
% hObject handle to edit_fileName (see GCBO)
% eventdata reserved - to be defined in a future version of MATLAB
% handles structure with handles and user data (see GUIDATA)
% Hints: get(hObject,'String') returns contents of edit_fileName as text
% str2double(get(hObject,'String')) returns contents of edit_fileName as a double
% --- Executes during object creation, after setting all properties.
function edit_fileName_CreateFcn(hObject, eventdata, handles)
% hObject handle to edit_fileName (see GCBO)
% eventdata reserved - to be defined in a future version of MATLAB
% handles empty - handles not created until after all CreateFcns called