lat = [47.5, 45.5, 46.5]';
lon = [-63.5, -61.5, -62.5]';
pts_name = {'A'; 'B'; 'C'};
pts_positions = table(pts_name, 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
pts_position_assigned = vertcat(assigned{:});
2 Comments
Direct link to this comment
https://in.mathworks.com/matlabcentral/answers/502895-how-to-assign-points-to-one-or-several-boxes#comment_791936
Direct link to this comment
https://in.mathworks.com/matlabcentral/answers/502895-how-to-assign-points-to-one-or-several-boxes#comment_791936
Direct link to this comment
https://in.mathworks.com/matlabcentral/answers/502895-how-to-assign-points-to-one-or-several-boxes#comment_791938
Direct link to this comment
https://in.mathworks.com/matlabcentral/answers/502895-how-to-assign-points-to-one-or-several-boxes#comment_791938
Sign in to comment.