forked from CamachoDejay/polymer3D
-
Notifications
You must be signed in to change notification settings - Fork 3
Expand file tree
/
Copy pathmainPlotTraces.m
More file actions
140 lines (109 loc) · 3.18 KB
/
mainPlotTraces.m
File metadata and controls
140 lines (109 loc) · 3.18 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
%%
% This code assumes that some trackRes has been loaded onto matlab
% no clearing
clc
close all
%% User input
path2Save = 'E:\Results\SPT speed\FINAL VERSION\pH 11';
ext = '.gif';
filename=sprintf('%s%sdata%s', path2Save,filesep,ext);
minSize = 20;%number of frame the traces needs to last to be plotted.
expTime = 0.11; %sec
sizeParticles = 2000; % diameter in nm
frameRate = 10;
trailing = 20; %frame the traces stays in the movie
%% Plot all Traces with time color-coding (4D plot)
CM = zeros(size(trackRes.traces,1),3);
maxFr = zeros(size(trackRes.traces,1),1);
figure
hold on
for i = 1:size(trackRes.traces,1)
currTrace = trackRes.traces{i,1};
if height(currTrace) > minSize
colPlot = currTrace.col;
rowPlot = currTrace.row;
zPlot = currTrace.z;
tPlot = currTrace.t*expTime;
plot3(colPlot,rowPlot,zPlot)
%plot with time color coding
patch([colPlot(:)' nan],[rowPlot(:)' nan],[zPlot(:)' nan],[tPlot(:)' nan],'EdgeColor','interp','FaceColor','none')
end
CM(i,:) = [mean(currTrace.row),mean(currTrace.col),mean(currTrace.z)];
maxFr(i,:) = max(currTrace.t);
end
CM = mean(CM,1);
maxFr = max(maxFr);
axis image
%% Make Awesome movie
radius = 1000;
yLimit = [0 35000];
xLimit = [0 25000];
zLimit = [-2000 2000];
Fig = figure;
view(3);
xlim(xLimit);
ylim(yLimit);
zlim(zLimit);
xlim manual;
ylim manual;
gcf;
hold on
[x,y,z] = sphere(32);
x = x*sizeParticles/2;
y = y*sizeParticles/2;
z = z*sizeParticles/2;
camlight
lighting('gouraud');
for i = 1 :maxFr
for j = 1:size(trackRes.traces,1)
currTrace = trackRes.traces{j,1};
if height(currTrace) > minSize
idx2Frame = currTrace.t==i;
idx = i-trailing:i;
idx = ismember(currTrace.t,idx);
if and(~all(idx==0), ~all(idx2Frame ==0))
data2Plot = currTrace(idx,:);
axis image
xlim(xLimit);
ylim(yLimit);
zlim(zLimit)
xlim manual;
ylim manual;
zlim manual;
view(3);
gcf;
hold on
plot3(data2Plot.col,data2Plot.row,data2Plot.z,'color',[0 0 1])
X = x+currTrace.col(idx2Frame);
Y = y+currTrace.row(idx2Frame);
Z = z+currTrace.z(idx2Frame);
surf(X,Y,Z,'LineStyle','none','Facecolor',[0.4,0.4,0.4])
end
end
end
drawnow;
frame = getframe(Fig);
im = frame2im(frame);
[imind,cm] = rgb2ind(im,256);
if i == 1
imwrite(imind,cm,filename,'gif','DelayTime',1/frameRate, 'loopcount',inf);
else
imwrite(imind,cm,filename,'gif','DelayTime',1/frameRate, 'writemode','append');
end
clf;
end
%% plot only a single traced
figure
idx = 7;
currTrace = trackRes.traces{idx,1};
colPlot = currTrace.col;
rowPlot = currTrace.row;
zPlot = currTrace.z;
tPlot = currTrace.t*expTime;
patch([colPlot(:)' nan],[rowPlot(:)' nan],[zPlot(:)' nan],[tPlot(:)' nan],'EdgeColor','interp','FaceColor','none')
view(3)
colorbar
xlabel('Position (nm)')
ylabel('Position (nm)')
zlabel('Position (nm)')
axis image