-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathRemove_Paths_In_Grids.m
76 lines (65 loc) · 2.93 KB
/
Remove_Paths_In_Grids.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
function [NPos_x,NPos_y] = Remove_Paths_In_Grids(NPos_x,NPos_y,grids,apts,cell_grids)
%% Inputs
%NPos_x,NPos_y - full trajectories of all particles
%grids - number of grids = n
%apts - number of apertures = m
%cell_grids - a nxm cell full of 1x4 columns of the points that make up
%each grid
%For example:
% grid 1 grid 2
% Aperture 1 {[X1;Y1;X2;Y2],[X3;Y3;X4;Y4];
% Aperture 2 [X1;Y1;X2;Y2],[X3;Y3;X4;Y4]}
% %% Plot everything (comment this out if you don't want to plot
% subplot(1,2,1)
% for o = 1:size(NPos_x,1)
% plot(NPos_x(o,:),NPos_y(o,:),'-')
% hold on
% end
% hold on
%% Remove trajectories that go into the grids
% gridsX, gridsY
%NPos_x, NPos_y
%Create a function
%It will mostly go into accel grid
%check x coord first - If x is within range, then check y data
%Stop it comepletely if it enters the grid
for n = 1:apts %Number of grids
for m = 1:grids %number of apertures
%Find the coordinates for the grids
gridsX1 = cell_grids{m}(n,1); %X1
gridsY1 = cell_grids{m}(n,2); %Y1
gridsX2 = cell_grids{m}(n,3); %X2
gridsY2 = cell_grids{m}(n,4); %Y2
gridsX3 = cell_grids{m}(n+1,1); %X3
gridsX4 = cell_grids{m}(n+1,3); %X4
for i = 1:size(NPos_x,1)%Run through the number of particles
run = 1; %Enter the while loop
j=1; %Start with the first positon of the particle
while run == 1 && j < size(NPos_x,2)%Run as long as the particle stays outside of the grids
if NPos_x(i,j) > gridsY1 && NPos_x(i,j) < gridsY2 && NPos_y(i,j) < gridsX2 && NPos_y(i,j) > gridsX1 %Compare first grid values
for k = j:size(NPos_x,2)
%Make the rest of the values in the array zero
NPos_x(i,k) = 0;
NPos_y(i,k) = 0;
end
run = 0; %End the while loop once the particle enters the grids
elseif NPos_x(i,j) > gridsY1 && NPos_x(i,j) < gridsY2 && NPos_y(i,j) > gridsX3 && NPos_y(i,j) < gridsX4
for k = j:size(NPos_x,2)
%Make the rest of the values in the array zero
NPos_x(i,k) = 0;
NPos_y(i,k) = 0;
end
run = 0; %End the while loop once the particle enters the grids
end
j = j+1;
end
end
end
end
end
% %% Plot afterwards (comment out if unecessary)
% subplot(1,2,2)
% for o = 1:size(NPos_x,1)
% plot(NPos_x(o,:),NPos_y(o,:),'-')
% hold on
% end