histogram of a a function with two variable

4 vues (au cours des 30 derniers jours)
george veropoulos
george veropoulos le 23 Mai 2021
Hi
i have a function f of two variable h and psi i want to make the histogram of f in 2 dimensio ( h, psi)
h follow an unifrom distrubution in range [h1,h2 ] and PSI follow an uniform distribution in [0, π/2]
thank you
George
  8 commentaires
Paul
Paul le 23 Mai 2021
Again, what do you mean by "hist of function f"? Normally, a 2D histogram is computed from pairs of data. But you have triplets (h,psi,f) so it's not clear what you want to plot.
george veropoulos
george veropoulos le 24 Mai 2021
i find the solution i plot the values of f with the function histtogram

Connectez-vous pour commenter.

Réponse acceptée

Rik
Rik le 23 Mai 2021
A histogram in two dimensions:
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 functions named histogram2 tall/histogram2
So now you only need to calculate the X and Y matrices based on your two vectors and your function. If your function allows array inputs you can use the output from either meshgrid or ndgrid. If not, you can either use a loop, or use arrayfun.
  4 commentaires
Rik
Rik le 24 Mai 2021
Which part do you have trouble implementing? Creating the vectors? (since you want flat distributions, evn linspace would do the trick) Putting those vectors in ndgrid or meshgrid to create matrices? Calculating the value for each pair? Calling histogram2?
Also, if you don't share your function, how can I write code specific to your question?
Try each step, show what you've done and and ask a specific question.
george veropoulos
george veropoulos le 24 Mai 2021
I find he solution a simple hist diagram cover me

Connectez-vous pour commenter.

Plus de réponses (0)

Community Treasure Hunt

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

Start Hunting!

Translated by