-
Notifications
You must be signed in to change notification settings - Fork 4
/
getplotrange.m
237 lines (154 loc) · 7.59 KB
/
getplotrange.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
% getplotrange.m
% Gets the plot range according to file number from the text box.
load maindata.mat
load configdata.mat
if exist('dataplotterstore.mat','file') == 2
load dataplotterstore.mat
end
filerange = get(handles.edit_dataplot_range,'String'); % grabs text from text box
filesToPlot = textscan(filerange, '%s','delimiter',',');
filesToPlot = filesToPlot{1};
for count = 1:length(filesToPlot)
ranges{count} = textscan(filesToPlot{count}, '%s','delimiter','-');
end
if plotstate == 1 % for plotting saved data
if plotdata_sp1 == 1
loadlogPlotter_sp1; % loads saved data log file
dataCellIndices = strfind(lfc_sp1{2},rootPlot); % finds cells with correct date (can't use "find" function for cells)
dataCellMatrix = ~cellfun('isempty',dataCellIndices); % gets nonzero
dataIndex_sp1 = find(dataCellMatrix);
end
%if (twospecies == 1) && (plotspecies2 == 1)
if plotdata_sp2 == 1
loadlog_sp2; % loads saved data log file
dataCellIndices = strfind(lfc_sp2{2},rootPlot); % finds cells with correct date (can't use "find" function for cells)
dataCellMatrix = ~cellfun('isempty',dataCellIndices); % gets nonzero
dataIndex_sp2 = find(dataCellMatrix);
end
end
for count = 1:length(ranges)
lowest(count) = round(str2num(ranges{count}{1}{1}));
if length(ranges{count}{1}) == 2
if strcmp(ranges{count}{1}{2},'end')
if plotstate == 0
if exist('counter_store_sp1','var') && exist('counter_store_sp2','var')
highest(count) = max([max(counter_store_sp1) max(counter_store_sp2)]);
elseif exist('counter_store_sp1','var') && ~exist('counter_store_sp2','var')
highest(count) = max(counter_store_sp1);
elseif ~exist('counter_store_sp1','var') && exist('counter_store_sp2','var')
highest(count) = max(counter_store_sp2);
end
else
if (plotdata_sp1 == 1) && (plotdata_sp2 == 0)
highest(count) = str2num(cell2mat(lfc_sp1{3}(max(dataIndex_sp1))));
elseif (plotdata_sp1 == 0) && (plotdata_sp2 == 1)
highest(count) = str2num(cell2mat(lfc_sp2{3}(max(dataIndex_sp2))));
elseif (plotdata_sp1 == 1) && (plotdata_sp2 == 1)
highest_sp1 = str2num(cell2mat(lfc_sp1{3}(max(dataIndex_sp1))));
highest_sp2 = str2num(cell2mat(lfc_sp2{3}(max(dataIndex_sp2))));
highest(count) = max([highest_sp1 highest_sp2]);
end
end
else
highest(count) = round(str2num(ranges{count}{1}{2}));
end
else
highest(count) = 0;
end
end
remindex = [];
for count = 1:length(ranges)
if highest(count) ~= 0
remindex(length(remindex)+1:length(remindex)+(highest(count)-lowest(count))+1) = lowest(count):1:highest(count);
else
remindex(length(remindex)+1) = lowest(count);
end
end
% Find index of stored data
if plotstate == 0 % new data
if ~isempty(remindex)
for ii = 1:1:length(remindex)
%if (twospecies == 1) && (plotspecies2 == 1)
if (plotdata_sp1 == 1) && (plotdata_sp2 == 1)
file_index_sp1 = find(counter_store_sp1 == remindex(ii));
if plotspecies2 == 1
file_index_sp2 = find(counter_store_sp2 == remindex(ii));
end
%elseif (sepspecies == 1) && (plotspecies2 == 1)
elseif (plotdata_sp1 == 0) && (plotdata_sp2 == 1) && (plotspecies2 == 1)
if exist('counter_store_sp1','var') && exist('counter_store_sp2','var')
file_index_sp2 = find(counter_store_sp2 == remindex(ii));
elseif exist('counter_store_sp1','var') && ~exist('counter_store_sp2','var')
file_index_sp1 = find(counter_store_sp1 == remindex(ii));
elseif ~exist('counter_store_sp1','var') && exist('counter_store_sp2','var')
file_index_sp2 = find(counter_store_sp2 == remindex(ii));
end
else
file_index_sp1 = find(counter_store_sp1 == remindex(ii));
end
%if (sepspecies == 0) || ((sepspecies == 1) && (plotspecies2 == 0))
if plotdata_sp1 == 1
if isempty(file_index_sp1)
file_index_string = num2str(remindex(ii));
% datamsg = msgbox(['File ' file_index_string ' does not exist!']);
else
stored_index_sp1(ii) = file_index_sp1;
end
end
%if ((twospecies == 1) && (plotspecies2 == 1)) || ((sepspecies == 1) && (plotspecies2 == 1))
if (plotdata_sp2 == 1) && (plotspecies2 == 1)
if ~isempty(file_index_sp2)
stored_index_sp2(ii) = file_index_sp2;
end
end
end
else
if plotdata_sp1 == 1
stored_index_sp1 = [];
end
if plotdata_sp2 == 1
stored_index_sp2 = [];
end
end
else % saved data
if ~isempty(remindex)
for ii = 1:1:length(remindex)
if plotdata_sp1 == 1
filePos_cell = ismember(lfc_sp1{3}(dataIndex_sp1),num2str(remindex(ii)));
file_index_sp1 = find(filePos_cell) + min(dataIndex_sp1) - 1;
if ~isempty(file_index_sp1)
stored_index_sp1(ii) = file_index_sp1;
end
end
if plotdata_sp2 == 1
filePos_cell = ismember(lfc_sp2{3}(dataIndex_sp2),num2str(remindex(ii)));
file_index_sp2 = find(filePos_cell) + min(dataIndex_sp2) - 1;
if ~isempty(file_index_sp2)
stored_index_sp2(ii) = file_index_sp2;
end
end
end
else % what do do if data plotter asks for images that don't exist
if plotdata_sp1 == 1
stored_index_sp1 = [];
end
if plotdata_sp2 == 1
stored_index_sp2 = [];
end
end
end
if plotstate == 0 % new data
if plotdata_sp1 == 1
stored_index_sp1 = stored_index_sp1(find(stored_index_sp1));
end
if (plotdata_sp2 == 1) && (plotspecies2 == 1)
stored_index_sp2 = stored_index_sp2(find(stored_index_sp2));
end
else % saved data
if plotdata_sp1 == 1
stored_index_sp1 = stored_index_sp1(find(stored_index_sp1));
end
if plotdata_sp2 == 1
stored_index_sp2 = stored_index_sp2(find(stored_index_sp2));
end
end