How to repeatedly subdive vector rectangle into equal area?
Show older comments
I have x,y point data that I am trying to analyze in "swaths" or rectangles along the x-axis. I need to take the rectangle and subdivide it into equal areas, and count the number of areas that contain points.
Consider this example with a very small x,y dataset:
% make dummy data
x = 10*rand(30,1);
y = 25*rand(30,1);
% set up basis for building swaths or rectangles
step = 1;
xmax = step*(ceil(max(x)/step)); % rounds up to nearest step size
centers = 0:step/2:xmax;
centers = centers';
ymax = step*(ceil(max(y)/step));
%% will ultimately loop over all centers, but just consider one for now
jj = 2;
xr = [centers(jj-1), centers(jj+1), centers(jj+1), centers(jj-1), centers(jj-1)];
yr = [ymax+step, ymax+step, 0-step, 0-step, ymax+step];
% plot for discussion
scatter(x,y,'.')
box on
grid on
hold on
axis equal
plot(xr,yr,'blue')
% this gives point counts inside big rectangle as a sanity check
% but I need to do this for all the equal areas that I need to build
[in,on] = inpolygon(x,y,xr,yr);
num_points_example = sum(in);

So in this example, my blue rectangle is 26x1 units. To make equal areas, I need to keep the x-axis length the same (=1) and break the rectangle down into 26 square along the y-axis. My question is, how do I programmatically build a grid or mesh for this 26x1? Note that in the next step, I'll be subdividing it further (52x2), etc., always maintaining equal area. I only have the basic Matlab, no fancy toolboxes, R2018a.
Accepted Answer
More Answers (0)
Categories
Find more on Data Distribution Plots in Help Center and File Exchange
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!