4 views (last 30 days)

Show older comments

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.

Adam Danz
on 28 Jul 2021

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.

Adam Danz
on 31 Jul 2021

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).

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

Start Hunting!