Creating a cell for each plot grid

조회 수: 1(최근 30일)
Riccardo Tronconi 2021년 7월 28일
댓글: Adam Danz 2021년 7월 31일
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.

댓글을 달려면 로그인하십시오.

채택된 답변

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표시숨기기 이전 댓글 수: 3
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).

댓글을 달려면 로그인하십시오.

Community Treasure Hunt

Find the treasures in MATLAB Central and discover how the community can help you!

Start Hunting!

Translated by