lat = [47.5, 45.5, 46.5, 46.6, 47.8]';
lon = [-63.5, -61.5, -62.5, -62.4, -63.6]';
pts_positions = table(lat, lon);
box_name = {'box_A'; 'box_B'};
min_lat = [46, 45]';
max_lat = [48, 47]';
min_lon = [-64, -63]';
max_lon = [-62, -61]';
boxes_positions = table(box_name, min_lat, max_lat, min_lon, max_lon);
assigned = cell(height(boxes_positions),1);
for g = 1:height(boxes_positions)
mask = pts_positions.lon > boxes_positions.min_lon(g) & pts_positions.lon < boxes_positions.max_lon(g) & ...
pts_positions.lat > boxes_positions.min_lat(g) & pts_positions.lat < boxes_positions.max_lat(g);
temp = pts_positions(mask, :);
temp.box = repmat(box_name(g), height(temp), 1);
assigned{g} = temp;
end
box_a_pos = ismember(assigned{1}(:,1:2),assigned{2}(:, 1:2));
box_b_pos = ismember(assigned{2}(:,1:2),assigned{1}(:, 1:2));
assigned{1}(box_a_pos,:).box = strcat(assigned{1}(box_a_pos,:).box, ',', ...
assigned{2}.box{1});
assigned{2} = assigned{2}(~box_b_pos,:);
pts_position_assigned = vertcat(assigned{:});
lat = [47.5, 45.5, 46.5, 46.6, 47.8]';
lon = [-63.5, -61.5, -62.5, -62.4, -63.6]';
box = {'box_A', 'box_B', 'box_A,box_B', 'box_A,box_B', 'box_A'}';
output = table(lat, lon, box);
0 Comments
Sign in to comment.