-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathzoneTransitionCounter.m
More file actions
143 lines (130 loc) · 4.55 KB
/
zoneTransitionCounter.m
File metadata and controls
143 lines (130 loc) · 4.55 KB
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
clc;
clear;
% The variable "numberOfFiles" below here should reflect how many .txt files you have,
% The rest of the code works based off this number
% If the files are labeled from 0 to X, then this should equal "X + 1"
% If the files are labeled from 1 to X, then this should equal "X"
numberOfFiles = 25;
% This will create an Object called mice, if you want to know how these work
% generally look up object oriented programming (OOP), specifically classes
% or structs.
miceInputData = cell(numberOfFiles,1);
% The for loop below iterates through all of the files that are of format
% //"Test" + "some number associated" + ".txt"//.
for k = 1:numberOfFiles
fileName = sprintf('Test %d.txt', k);
temp = importdata(fileName);
miceInputData{k} = temp.data;
end
% /------------------------------------------------------------------------/
% DATA OVERVIEW=
% DATA(fileNumber, 1) = Closed Arms -> Open Arms Count /
% DATA(fileNumber, 2) = Open Arms -> Closed Arms Count /
% DATA(fileNumber, 3) = NAN Total /
% DATA(fileNumber, 4) = Length Of Data /
% DATA(fileNumber, 5) = Transitions Count
data = zeros(25,4);
% /------------------------------------------------------------------------/
% I will not comment on the code below, because it is rather inefficient
% and the correct answer was found by trying to track something
% incorrectly. There is a simpler way (less lines of code) to track the
% amount of transitions between open and closed arm zones, but hindsight if
% 20/20 and I was drunk when I started this code.
for k = 1:numberOfFiles
temp = miceInputData{k};
nanTotal = 0;
for i = 1:length(temp)
if (temp(i,3) == -1000 && temp(i,4) == -1000)
nanTotal = nanTotal + 1;
end
end
data(k,3) = nanTotal;
end
for k = 1:numberOfFiles
temp = miceInputData{k};
x = 2;
timeInClosed = 1;
timeInOpen = 1;
didLoop = 0;
for i = 1:length(temp)
if x >= length(temp)
break;
end
if (temp(x,3) == 1 )
y = x;
didLoop = 0;
while temp(y,3) == temp(y-1,3)
timeInClosed = timeInClosed + 1;
y = y + 1;
didLoop = 1;
if y > length(temp)
break;
end
%For debugging
%disp(y);
end
if didLoop == 1
x = y;
end
end
if x > length(temp)
break;
end
if (temp(x,4) == 1)
y = x;
didLoop = 0;
while temp(y,4) == temp(y-1,4)
timeInOpen = timeInOpen + 1;
y = y + 1;
didLoop = 1;
if y > length(temp)
break;
end
% For debugging
%disp(y);
end
if didLoop == 1
x = y;
end
end
if didLoop == 0
x = x + 1;
% For debugging
%disp(x);
end
end
data(k,4) = length(temp);
data(k,5) = data(k,4) - (timeInClosed + timeInOpen + data(k,3));
end
% /------------------------------------------------------------------------/
for k = 1:numberOfFiles
for i = 1:length(temp)
if (temp(i,3) ~= -1000 || temp(i,4) ~= -1000)
% Tells us if the mouse started in the closed arm zone first
% then outputs how many times the mouse went from open to
% closed and closed to open
if (temp(i,3) == 1)
data(k,1) = round(data(k,5) / 2);
data(k,2) = data(k,5) - data(k,1);
end
% Tells us if the mouse started in the open arm zone first
% then outputs how many times the mouse went from open to
% closed and closed to open
if (temp(i,4) == 1)
data(k,2) = round(data(k,5) / 2);
data(k,1) = data(k,5) - data(k,2);
end
% Once we know what zone a mouse started in, we move to the
% next mouse
break;
end
end
end
% /------------------------------------------------------------------------/
% File output loop
fileID = fopen('miceTransitionsCount.txt','w');
fprintf(fileID,'Mouse ID | Closed to Open | Open to Closed | Transition Count\n');
for k = 1:numberOfFiles
fprintf(fileID,'%d %d %d %d\n', k, data(k,1), data(k,2), data(k,5));
end
fclose(fileID);