Counting the number of data points inside grid

3 次查看(过去 30 天)
I need help with counting and updating the number of unlabelled data points inside each 2d grid after plotting the points randomly.

回答(1 个)

Image Analyst
Image Analyst 2012-5-12
Well, you plotted them so why don't you know the lengths of the arrays, or how many points you plotted?
  2 个评论
Don
Don 2023-9-6
Wow, super unhelpful. Maybe the source of data is from an outside source? A CSV perhaps? Came with same question; reading an unseen file for data, need to know how many data points I have.
Image Analyst
Image Analyst 2023-9-6
@Don I'd have been happy to help more and better if he had given some data, but he didn't and I was not sure how to answer the ambiguous question. If you cam with the same question, I can still answer if I know the data or source of the data. Normally if you read data in from an array you can use numel to see how many data points you have. If you have 2-D data and want to know how much is in some grid over the data that you have defined, you can use histogram2
help histogram2
HISTOGRAM2 Plots a bivariate histogram. HISTOGRAM2(X,Y) plots a bivariate histogram of X and Y. X and Y can be arrays of any shape, but they must have the same size. HISTOGRAM2 determines the bin edges using an automatic binning algorithm that returns uniform bins of an area chosen to cover the range of values in X and Y and reveal the shape of the underlying distribution. HISTOGRAM2(X,Y,NBINS), where NBINS is a scalar or 2-element vector, specifies the number of bins to use. A scalar specifies the same number of bins in each dimension, whereas the 2-element vector [nbinsx nbinsy] specifies a different number of bins for the X and Y dimensions. HISTOGRAM2(X,Y,XEDGES,YEDGES), where XEDGES and YEDGES are vectors, specifies the edges of the bins. The value [X(k),Y(k)] is in the (i,j)th bin if XEDGES(i) <= X(k) < XEDGES(i+1) and YEDGES(j) <= Y(k) < YEDGES(j+1). The last bins in the X and Y dimensions will also include the upper edge. For example, [X(k),Y(k)] will fall into the i-th bin in the last row if XEDGES(end-1) <= X(k) <= XEDGES(end) && YEDGES(i) <= Y(k) < YEDGES(i+1). HISTOGRAM2(...,'BinWidth',BW) where BW is a scalar or 2-element vector, uses bins of size BW. A scalar specifies the same bin width for each dimension, whereas the 2-element vector [bwx bwy] specifies different bin widths for the X and Y dimensions. To prevent from accidentally creating too many bins, a limit of 1024 bins can be created along each dimension when specifying 'BinWidth'. If BW is too small such that more than 1024 bins are needed in either dimension, HISTOGRAM2 uses larger bins instead. HISTOGRAM2(...,'XBinLimits',[XBMIN,XBMAX]) plots a histogram with only elements between the bin limits inclusive along the X axis, X>=BMINX & X<=BMAXX. Similarly, HISTOGRAM2(...,'YBinLimits',[YBMIN,YBMAX]) uses only elements between the bin limits inclusive along the Y axis, Y>=YBMIN & Y<=YBMAX. HISTOGRAM2(...,'Normalization',NM) specifies the normalization scheme of the histogram values. The normalization scheme affects the scaling of the histogram along the Z axis. NM can be: 'count' The height of each bar is the number of observations in each bin. The sum of the bar heights is generally equal to NUMEL(X) and NUMEL(Y), but is less than if some of the input data is not included in the bins.. 'probability' The height of each bar is the relative number of observations (number of observations in bin / total number of observations), and the sum of the bar heights is less than or equal to 1. 'countdensity' The height of each bar is, (the number of observations in each bin) / (area of bin). The volume (height * area) of each bar is the number of observations in the bin, and the sum of the bar volumes is less than or equal to NUMEL(X) and NUMEL(Y). 'pdf' Probability density function estimate. The height of each bar is, (number of observations in bin) / (total number of observations * area of bin). The volume of each bar is the relative number of observations, and the sum of the bar volumes is less than or equal to 1. 'cumcount' The height of each bar is the cumulative number of observations in each bin and all previous bins in both the X and Y dimensions. The height of the last bar is less than or equal to NUMEL(X) and NUMEL(Y). 'cdf' Cumulative density function estimate. The height of each bar is the cumulative relative number of observations in each bin and all previous bins in both the X and Y dimensions. The height of the last bar is less than or equal to 1. HISTOGRAM2(...,'DisplayStyle',STYLE) specifies the display style of the histogram. STYLE can be: 'bar3' Display histogram using 3-D bars. This is the default. 'tile' Display histogram as a rectangular array of tiles with colors indicating the bin values. HISTOGRAM2(...,'BinMethod',BM), uses the specified automatic binning algorithm to determine the number and width of the bins. BM can be: 'auto' The default 'auto' algorithm chooses a bin size to cover the data range and reveal the shape of the underlying distribution. 'scott' Scott's rule is optimal if X and Y are close to being jointly normally distributed, but is also appropriate for most other distributions. It uses a bin size of [3.5*STD(X(:))*NUMEL(X)^(-1/4) 3.5*STD(Y(:))*NUMEL(Y)^(-1/4)] 'fd' The Freedman-Diaconis rule is less sensitive to outliers in the data, and may be more suitable for data with heavy-tailed distributions. It uses a bin size of [2*IQR(X(:))*NUMEL(X)^(-1/4) 2*IQR(Y(:))*NUMEL(Y)^(-1/4)] where IQR is the interquartile range. 'integers' The integer rule is useful with integer data, as it creates a bin for each pair of integer X and Y. It uses a bin width of 1 along each dimension and places bin edges halfway between integers. To prevent from accidentally creating too many bins, a limit of 1024 bins can be created along each dimension with this rule. If the data range along either dimension is greater than 1024, then larger bins are used instead. HISTOGRAM2(...,NAME,VALUE) set the property NAME to VALUE. HISTOGRAM2('XBinEdges', XEDGES, 'YBinEdges', YEDGES, 'BinCounts', COUNTS) where COUNTS is a matrix of size [length(XEDGES)-1, length(YEDGES)-1], manually specifies the bin counts. HISTOGRAM2 plots the counts and does not do any data binning. HISTOGRAM2(AX,...) plots into AX instead of the current axes. H = HISTOGRAM2(...) also returns a Histogram2 object. Use this to inspect and adjust the properties of the histogram. Class support for inputs X, Y, XEDGES, YEDGES: float: double, single integers: uint8, int8, uint16, int16, uint32, int32, uint64, int64 logical See also HISTCOUNTS2, HISTCOUNTS, HISTOGRAM, DISCRETIZE, matlab.graphics.chart.primitive.Histogram2 Documentation for histogram2 doc histogram2 Other uses of histogram2 tall/histogram2
You can set up the "edges" to define where the gridlines are. If you want more help, attach your data file in a new question.

请先登录,再进行评论。

类别

Help CenterFile Exchange 中查找有关 Bar Plots 的更多信息

标签

Community Treasure Hunt

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

Start Hunting!

Translated by