How to count points inside each grid cell with central value of each grid cell?

4 ビュー (過去 30 日間)
Andi
Andi 2022 年 6 月 2 日
コメント済み: Walter Roberson 2022 年 6 月 2 日
Hi everyone,
I have created a mashgrid to plot my data points with each small bins (figure attached). Now, I need to count data points within each bin along with the cental value of each grid cell.
Here is my attempt:
x = -130.05:0.01:-129.95;
y = 45.90:0.01:46.00;
n = length(x ) ;
m = length(y ) ;
[X,Y] = meshgrid(x,y ) ;
x = axil_long ; y = axil_lat ; z = time_axil(:,1) ;
plot(X,Y,'r',X',Y','r ')
hold on
for i = 1:m-1
for j = 1:n-1
P = [X(i,j) Y(i,j ) ;
X(i,j+1) Y(i,j+1 ) ;
X(i+1,j+1) Y(i+1,j+1 ) ;
X(i+1,j) Y(i+1,j )] ;
idx = inpolygon(x,y,P(:,1),P(:,2 )) ;
iwant = [ z(idx )] ;
plot(x(idx),y(idx ),'.')
zStore{i,j} = z(idx);
end
end
  3 件のコメント
Andi
Andi 2022 年 6 月 2 日
Thanks, but how I can get the central (x, y) for each grid
Walter Roberson
Walter Roberson 2022 年 6 月 2 日
take the second and third outputs, which will be the edges.
xcent = (XEdges(1:end-1) +XEdges(2:end))/2

サインインしてコメントする。

回答 (0 件)

カテゴリ

Help Center および File ExchangeData Import and Network Parameters についてさらに検索

タグ

製品

Community Treasure Hunt

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

Start Hunting!

Translated by