How do I measure density of random point with a fixed area in MATLAB?

11 ビュー (過去 30 日間)
Chun Yin Lui
Chun Yin Lui 2021 年 1 月 20 日
コメント済み: Adam Danz 2021 年 12 月 21 日
There had a 9x9 area and I have generate a lot of point with this area in random.
How do I measure density of the red point (e.g. Bottom left).
Somebody can give something sample code to let me study with this topic? It is very helpful to my project research.
  3 件のコメント
Chun Yin Lui
Chun Yin Lui 2021 年 1 月 21 日
As for the code "plot(x,y,'*g',x(ind),y(ind),'or');"
Sorry for what is the '*g' and 'or'?
Dose it is the funtion of matlab or something etc?
Mathieu NOE
Mathieu NOE 2021 年 1 月 21 日
hello
these are plot format option * = star, g = green, o = circle , r = red

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

採用された回答

Adam Danz
Adam Danz 2021 年 1 月 20 日
編集済み: Adam Danz 2021 年 1 月 20 日
Use histogram2() or histcounts2() to compute 2D density.
Demo:
xy = randi(400,50,2);
subplot(1,2,1)
plot(xy(:,1), xy(:,2), 'r.')
axis equal
grid on
xlim([1,400])
ylim([1,400])
title('raw data')
binEdges = linspace(1,400,4);
set(gca,'XTick',binEdges, 'YTick',binEdges)
% Compute density in 3X3 bins
subplot(1,2,2)
h = histogram2(xy(:,1), xy(:,2), binEdges,binEdges,...
'DisplayStyle','tile','ShowEmptyBins','on');
axis equal
grid on
xlim([1,400])
ylim([1,400])
title('Density')
set(gca,'XTick',0:100:400, 'YTick',0:100:400)
cb = colorbar();
ylabel(cb,'Density')
% To label counts
[xTxt, yTxt] = ndgrid(h.XBinEdges(2:end)-h.BinWidth(1)/2, ...
h.YBinEdges(2:end)-h.BinWidth(2)/2);
labels = compose('%.0f', h.Values);
hold on
text(xTxt(:), yTxt(:), labels(:), 'VerticalAlignment', 'Middle', 'HorizontalAlignment','Center')
  12 件のコメント
ytu1990
ytu1990 2021 年 12 月 21 日
After calculating the density, how to return the density value to be linked to the coordinate of original point?
For example, return the value "9" to the points in the (1,1) grid...
Adam Danz
Adam Danz 2021 年 12 月 21 日
See h.Values

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

その他の回答 (0 件)

カテゴリ

Help Center および File ExchangeAnnotations についてさらに検索

製品


リリース

R2020a

Community Treasure Hunt

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

Start Hunting!

Translated by