count of points in particular region from graph

32 ビュー (過去 30 日間)
SINDU GOKULAPATI
SINDU GOKULAPATI 2021 年 5 月 6 日
コメント済み: Housam Mohammad 2023 年 8 月 23 日
graph is plot of scattered points , graph is also divided into grids of size 64*64. i need the count of number of points in each grid .
if a 32*32 (-1024 to 1024)matrix is taken such that each grid is represented by a value(count ) in matrix . any help is highly appretiated thanks

採用された回答

DGM
DGM 2021 年 5 月 6 日
編集済み: DGM 2021 年 5 月 6 日
Look at histcounts2():
% make some scattered points
npoints = 1000;
x = randn(npoints,1)*500;
y = randn(npoints,1)*300;
% plot them (just for sake of demonstration)
scatter(x,y); grid on;
xlim([-1024 1024])
ylim([-1024 1024])
% define bin edges and find bin counts
edx = -1024:64:1024;
edy = -1024:64:1024;
counts = histcounts2(x,y,edx,edy).';
Play around with it with some asymmetric data so you understand the orientation of the output. You may find it more intuitive to transpose the counts array like I did here.
If you want to visualize the results:
imshow(counts,[])
(scaled up, obviously)
  2 件のコメント
SINDU GOKULAPATI
SINDU GOKULAPATI 2021 年 5 月 6 日
編集済み: SINDU GOKULAPATI 2021 年 5 月 6 日
hey, thanks its works perfectly
i also have a follow up
so from the fig if i want the number of points in those consentric region , how can i do that ?
so here in red region 2 points and in blue 1 points and so on.... givind the output as an array (basically add the concentic areas in the counts matrix)
DGM
DGM 2021 年 5 月 6 日
編集済み: DGM 2021 年 5 月 6 日
Something like this.
% find sums of annular rings of counts
s = size(counts);
maxr = min(s(1:2))/2;
annularcounts = zeros(maxr,1);
corners = [s(1) s(2)]+1;
for a = 1:floor(maxr)
corners = corners-1;
l = corners-a+1;
A = counts(a:corners(1),a);
B = counts(corners(1),a:corners(2)).';
C = counts(corners(1):-1:a,corners(2));
D = counts(a,corners(2):-1:a).';
annularcounts(a) = sum(cat(1,A,B,C,D));
end
plot(maxr:-1:1,annularcounts); grid on
xlabel('radius from center of histogram')
ylabel('total count in annulus')
Which kind of makes sense. The peak density is at the center, but the area is also the smallest.

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

その他の回答 (1 件)

KSSV
KSSV 2021 年 5 月 6 日
You can proceed like below demo example:
clc; clear all ;
a = 1; b = 10 ;
x = (b-a).*rand(1000,1) + a;
y = (b-a).*rand(1000,1) + a;
[X,Y] = meshgrid(a:b,a:b) ;
plot(x,y,'.r')
hold on
plot(X,Y,'k',X',Y','k')
% number of points lying inside box (1,1) and (2,2)
idx = (x > 1) & (x <= 2) ;
idy = (y > 1) & (y <= 2) ;
id = idx & idy ;
plot(x(id),y(id),'ob')
fprintf('The number of points lying inside box (1,1) and (2,2) are %d\n',nnz(id))
  2 件のコメント
SINDU GOKULAPATI
SINDU GOKULAPATI 2021 年 5 月 6 日
it works but ig its again a long procedure to get for each area
Housam Mohammad
Housam Mohammad 2023 年 8 月 23 日
Elegent answer @KSSV, Thank you.

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

カテゴリ

Help Center および File ExchangeGraph and Network Algorithms についてさらに検索

タグ

Community Treasure Hunt

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

Start Hunting!

Translated by