How to analyse this data set?

1 view (last 30 days)
Mo Ba
Mo Ba on 4 May 2017
Edited: KSSV on 4 May 2017
Hello experts,
I have some data points and can easily plot them on a figure in MATLAB. For some reason, I need to find out what data points are located inside some rectangle areas as can be seen in attached picture. In this picture, black dots represent my data points and red rectangles represent mentioned areas. In this example, how can I search into my data points and see whether they belong to any rectangle or not? I need to have a list of all members (data points) for each rectangle. I hope I explained my problem clearly. Any idea and advice is appreciated.

Accepted Answer

KSSV
KSSV on 4 May 2017
Edited: KSSV on 4 May 2017
doc inpolygon
N = 30 ;
[X,Y] = meshgrid(1:N,1:N) ;
plot(X,Y,'.k','markersize',10) ;
%%polygon coordinates
Rect = [ 8.5369 23.4840
17.4539 23.4840
17.5230 16.7493
7.6382 16.4869
8.5369 23.4840] ;
hold on
plot(Rect(:,1),Rect(:,2),'r');
%%get points inside the polygon
idx = inpolygon(X,Y,Rect(:,1),Rect(:,2)) ;
%%points inside polygon
xi = X(idx) ; yi = Y(idx) ;
plot(xi,yi,'ob')

More Answers (0)

Community Treasure Hunt

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

Start Hunting!