forked from jstaf/fly_tracker
-
Notifications
You must be signed in to change notification settings - Fork 2
/
Copy pathstackTrace.m
67 lines (55 loc) · 1.6 KB
/
stackTrace.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
%% initialize
% Create a set of stacked position traces.
% if true, will not offset positions based on a fly's starting point
preserveOrigin = false;
% size of the arena
bounds = 8;
%% open files
% This file opens a set of position traces and stacks and plots them on the
% same set of coordinates.
inputFiles = uipickfiles();
if (isempty(inputFiles))
disp('No files selected.');
break;
end
% catch the 1 file error
if (isa(inputFiles,'char'))
inputFiles = {inputFiles};
end
%% make plots
% plot files individually
figure('Name', 'Stacked position traces');
% read files and plot trace
colormap = jet(length(inputFiles));
hold on;
for fileNum = 1:length(inputFiles)
replicate = csvread(char(inputFiles(fileNum)));
% remove NaNs
for col = 2:size(replicate,2)
column = replicate(:, col);
column = column(~isnan(column));
replicate(1:length(column),col) = column;
end
replicate = replicate(1:length(column), :);
% preliminary filtering
replicate = distFilter(replicate, 1);
if ~preserveOrigin
% normalize to first point
for col = 2:size(replicate,2)
replicate(:, col) = replicate(:, col) - replicate(1, col);
end
end
plot(replicate(:,2), replicate(:,3), ...
'linew', 1.5, 'LineSmoothing', 'on', ...
'color', colormap(fileNum, :));
end
hold off;
axis('equal', 'manual');
set(gca, 'Ydir', 'reverse');
if preserveOrigin
axis([0, bounds, 0, bounds]);
else
axis([-bounds, bounds, -bounds, bounds]);
end
plotLabel = cleanLabels(inputFiles);
legend(plotLabel, 'location', 'eastoutside');