How to divide an area having multiple random points and work on each part separately?
3 views (last 30 days)
Show older comments
I have asked this question before but couldnt get a satisfactory answer, so let me explain it a bit more, maybe i can make myself more clear.
I have scattered 100 points randomly in a 100x100 plot and divided that area into 9 grids.
a=rand(2,100)*100;
scatter(a(1,:),a(2,:))
grid on
set(gca,'xtick',[0:33.33333:100])
set(gca,'ytick',[0:33.33333:100])
Now I want to get some idea that how can I make groups for each grid (having points within) so that I can work on each grid separately.
Any help will be appreciated, thanks a lot!
4 Comments
Accepted Answer
Jan
on 10 May 2017
Edited: Jan
on 10 May 2017
Perhaps something like this simple loops:
a = rand(2,100)*100;
grid = 0:33.33333:100;
Result = cell(numel(grid) - 1, numel(grid) - 1);
for i1 = 1:numel(grid) - 1
for i2 = 1:numel(grid) - 1
index = (grid(i1) <= a(1, :) & a(1, :) < grid(i1 + 1) & ...
grid(i2) <= a(2, :) & a(2, :) < grid(i2 + 1));
Result{i1, i2} = a(index);
end
end
[EDITED] Now the points in the grid element [i,j] are store in the cell Result{i,j}.
3 Comments
More Answers (1)
Image Analyst
on 10 May 2017
Use max, min, and linspace.
4 Comments
Salma Hassan
on 10 May 2017
mr.image analyst i sent you a comment in this link : https://www.mathworks.com/matlabcentral/answers/177316-how-to-show-my-extracted-features#comment_451853
plz can you see it
See Also
Categories
Find more on Creating and Concatenating Matrices 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!