split plane into set of squares

조회 수: 4 (최근 30일)
Hassan
Hassan 2019년 4월 15일
답변: DGM 2024년 10월 2일
If I have set of (X,Y) points in a plane, how can I divide this plane into set of squares (with side lenght K), for example 10x10 squares to cover all the plane? the square #1 should start from (Xmin,Ymin)
X 1.33 1.89 9.27 9.46 9.2 7.43 6.08 5.57 6.7
Y 8.89 0.77 1.49 9.36 8.69 1.61 1.34 4.6 2.77
Then how can I know how many point in each square? such that
Square #1 have two points
.
Square #50 have zero point
.
Square #100 have one point

답변 (1개)

DGM
DGM 2024년 10월 2일
It's not clear where the bin limits actually are, but:
% the data
x = [1.33 1.89 9.27 9.46 9.20 7.43 6.08 5.57 6.70];
y = [8.89 0.77 1.49 9.36 8.69 1.61 1.34 4.60 2.77];
% edge breakpoints
tiling = [10 10]; % [x y]
xedges = linspace(min(x),max(x),tiling(1));
yedges = linspace(min(y),max(y),tiling(2));
% the member counts
counts = histcounts2(x,y,xedges,yedges)
counts = 9×9
1 0 0 0 0 0 0 0 1 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 1 0 0 0 0 1 0 1 0 0 0 0 0 0 1 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 1 0 0 0 0 0 0 0 2
<mw-icon class=""></mw-icon>
<mw-icon class=""></mw-icon>
% visualize the same thing
histogram2(x,y,xedges,yedges);

카테고리

Help CenterFile Exchange에서 Elementary Math에 대해 자세히 알아보기

태그

Community Treasure Hunt

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

Start Hunting!

Translated by