Creating a cell for each plot grid
5 次查看(过去 30 天)
显示 更早的评论
Hi guys! I'm struggling with this problem.
At first I would like to display an empty graph spaced by 2. For this purpose both axes have value from 0 to 10 stepped by 2.
Secondly, I would like to associate to each subgrid to a square polygon let's assume P1=(0,0) P2=(2,0) P3=(0,2) P4=(2,2).
At this point I would like to check for whichever point in the space if they belong or not to this polygon.
If yes, I need to save in a cell/table all information related to the point namely X and Y coordinates and timestamp.
Thanks to all in advance.
0 个评论
采纳的回答
Adam Danz
2021-7-28
At first I would like to display an empty graph spaced by 2. For this purpose both axes have value from 0 to 10 stepped by 2.
After generating the axes, set the XTick and YTick to 0:2:10.
Secondly, I would like to associate to each subgrid to a square polygon let's assume P1=(0,0) P2=(2,0) P3=(0,2) P4=(2,2).
I interpret this as I would like to add a polygon to the axes. If the polygon is rectangular and parallel to the axes use
rectangle('position',[L,B,W,H])
where L and B are the (x,y) coordinates for the left, bottom corner and W and H are width and height.
Otherwise you can use polyshape or patch.
At this point I would like to check for whichever point in the space if they belong or not to this polygon.
If yes, I need to save in a cell/table all information related to the point namely X and Y coordinates and timestamp.
Use the outputs of inpolygon in a conditional statement. Set up a table that has a column for the variables you listed above and add values to the table as needed.
If you get stuck on any of the steps above, share your updated code and point out the problem so we can help get you unstuck.
4 个评论
Adam Danz
2021-7-31
Since you don't need to display the rectangles, you just need to know which rectangle a dot belongs to.
That's what histcounts2() does. Here's a demo.
% Create random variable within the x & y extent
rng(210731) % for reproducibility
xy = rand(1,2)*10
% Determine where the random coordinate is within
% a grid of 2x2 rectangles extending from 0 to 10.
N = histcounts2(xy(1), xy(2), 0:2:10, 0:2:10)
This shows that coorinate (4.15, 7.06) falls into grid (3,4).
更多回答(0 个)
另请参阅
类别
在 Help Center 和 File Exchange 中查找有关 Computational Geometry 的更多信息
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!