-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathPI_right_Punish.m
90 lines (80 loc) · 5.22 KB
/
PI_right_Punish.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
%%%%%%%%%This script is used to calculate the PI when punishment is on
%%%%%%%%%Right-negtive
function PIRightPunish = PI_right_Punish(time, angle);
%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%% PI calculation in pretest
pretestrow = find(time>0 & time < 121); %%%% pretest phase from 0s to 120s%%%
pretest = time(pretestrow);%%%%%%%%%% time value in pretest phase%%%
pretestVal = angle(pretestrow);%%%%%%% trace value in pretest phase%%
tarow = find(pretestVal>0); %%%%%%%%%% find which row that trace value>0, i.e when turning left%%%
RTP = pretest(tarow(2:end)); %%%%%%find at which time point, fly on left side%%%
preRightRow = tarow-1;
PRTP = pretest(preRightRow(2:end)); %%%%%%%%%the last time point before RTP, %%%%
ta = sum(RTP-PRTP); %%%%%the total time when fly on the left side, i.e. non punishment time%%
tb = 120 - ta; %%%%%%tb means punishment time,
pretestPI = (ta-tb)/(ta+tb)
%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%% PI calculation in train1
train1row = find(time>120 & time < 241); %%%% train1 phase from 120s to 240s%%%
train1 = time(train1row);%%%%%%%%%% time value in train1 phase%%%
train1Val = angle(train1row);%%%%%%% trace value in train1 phase%%
tarow = find(train1Val>0); %%%%%%%%%% find which row that trace value>0, i.e when turning left%%%
RTP = train1(tarow(2:end)); %%%%%%find at which time point, fly on right side,RTP = right time point%%%
preRightRow = tarow-1;
PRTP = train1(preRightRow(2:end)); %%%%%%%%%the last time point before RTP%%%%
ta = sum(RTP-PRTP); %%%%%the total time when fly on the left side, i.e. non punishment time%%
tb = 120 - ta; %%%%%%tb means punishment time,
train1PI = (ta-tb)/(ta+tb)
%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%% PI calculation in train2
train2row = find(time>240 & time < 361); %%%% train1 phase from 240s to 360s%%%
train2 = time(train2row);%%%%%%%%%% time value in train2 phase%%%
train2Val = angle(train2row);%%%%%%% trace value in train2 phase%%
tarow = find(train2Val>0); %%%%%%%%%% find which row that trace value>0, i.e when turning left%%%
RTP = train2(tarow(2:end)); %%%%%%find at which time point, fly on left side%%%
preRightRow = tarow-1;
PRTP = train2(preRightRow(2:end));%%%%%%%%%the last time point before RTP%%%%
ta = sum(RTP-PRTP); %%%%%the total time when fly on the left side, i.e. non punishment time%%
tb = 120 - ta; %%%%%%tb means punishment time,
train2PI = (ta-tb)/(ta+tb)
%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%PI calculation in test1
test1row = find(time>360 & time < 481); %%%% train1 phase from 360s to 480s%%%
test1 = time(test1row);%%%%%%%%%% time value in test1 phase%%%
test1Val = angle(test1row);%%%%%%% trace value in test1 phase%%
tarow = find(test1Val>0); %%%%%%%%%% find which row that trace value>0, i.e when turning left%%%
RTP = test1(tarow(2:end)); %%%%%%find at which time point, fly on left side%%%
preRightRow = tarow-1;
PRTP = test1(preRightRow(2:end));%%%%%%%%%the last time point before RTP%%%%
ta = sum(RTP-PRTP); %%%%%the total time when fly on the left side, i.e. non punishment time%%
tb = 120 - ta; %%%%%%tb means punishment time,
test1PI = (ta-tb)/(ta+tb)
%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%PI calculation in train3
train2row = find(time>480 & time < 601); %%%% train1 phase from 480s to 600s%%%
train2 = time(train2row);%%%%%%%%%% time value in train3 phase%%%
train2Val = angle(train2row);%%%%%%% trace value in train3 phase%%
tarow = find(train2Val>0); %%%%%%%%%% find which row that trace value>0, i.e when turning left%%%
RTP = train2(tarow(2:end)); %%%%%%find at which time point, fly on left side%%%
preRightRow = tarow-1;
PRTP = train2(preRightRow(2:end));%%%%%%%%%the last time point before RTP%%%%
ta = sum(RTP-PRTP); %%%%%the total time when fly on the left side, i.e. non punishment time%%
tb = 120 - ta; %%%%%%tb means punishment time,
train3PI = (ta-tb)/(ta+tb)
%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%% PI calculation in train4
train2row = find(time>600 & time < 721); %%%% train1 phase from 600s to 720s%%%
train2 = time(train2row);%%%%%%%%%% time value in train4 phase%%%
train2Val = angle(train2row);%%%%%%% trace value in train4 phase%%
tarow = find(train2Val>0); %%%%%%%%%% find which row that trace value>0, i.e when turning left%%%
RTP = train2(tarow(2:end)); %%%%%%find at which time point, fly on left side%%%
preRightRow = tarow-1;
PRTP = train2(preRightRow(2:end));%%%%%%%%%the last time point before RTP%%%%
ta = sum(RTP-PRTP); %%%%%the total time when fly on the left side, i.e. non punishment time%%
tb = 120 - ta; %%%%%%tb means punishment time,
train4PI = (ta-tb)/(ta+tb)
%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%% PI calculation in test2
train2row = find(time>720 & time < 841); %%%% train1 phase from 720s to 840s%%%
train2 = time(train2row);%%%%%%%%%% time value in test2 phase%%%
train2Val = angle(train2row);%%%%%%% trace value in test2 phase%%
tarow = find(train2Val>0); %%%%%%%%%% find which row that trace value>0, i.e when turning left%%%
RTP = train2(tarow(2:end)); %%%%%%find at which time point, fly on left side%%%
preRightRow = tarow-1;
PRTP = train2(preRightRow(2:end));%%%%%%%%%the last time point before RTP%%%%
ta = sum(RTP-PRTP); %%%%%the total time when fly on the left side, i.e. non punishment time%%
tb = 120 - ta; %%%%%%tb means punishment time,
test2PI = (ta-tb)/(ta+tb)