Read Image to Grayscale and Display It in a Histogram Matlab
histogram
Clarification
Histograms are a type of bar plot for numeric data that group the data into bins. After y'all create a Histogram
object, yous can modify aspects of the histogram by changing its property values. This is specially useful for quickly modifying the properties of the bins or changing the brandish.
Creation
Syntax
Description
case
histogram(
creates a histogram plot of X
)Ten
. The histogram
function uses an automatic binning algorithm that returns bins with a uniform width, chosen to cover the range of elements in X
and reveal the underlying shape of the distribution. histogram
displays the bins as rectangles such that the summit of each rectangle indicates the number of elements in the bin.
case
histogram(
uses a number of bins specified by the scalar, 10
,nbins
)nbins
.
instance
histogram(
sorts X
,edges
)10
into bins with the bin edges specified past the vector, edges
. Each bin includes the left edge, but does not include the right edge, except for the last bin which includes both edges.
histogram('BinEdges',
manually specifies bin edges and associated bin counts. edges
,'BinCounts',counts
)histogram
plots the specified bin counts and does non do whatsoever data binning.
example
histogram(
, where C
)C
is a categorical array, plots a histogram with a bar for each category in C
.
histogram(
plots but the subset of categories specified past C
,Categories
)Categories
.
histogram('Categories',
manually specifies categories and associated bin counts. Categories
,'BinCounts',counts
)histogram
plots the specified bin counts and does not do any data binning.
example
histogram(___,
specifies additional options with ane or more Proper noun,Value
)Name,Value
pair arguments using any of the previous syntaxes. For example, yous can specify 'BinWidth'
and a scalar to arrange the width of the bins, or 'Normalization'
with a valid option ('count'
, 'probability'
, 'countdensity'
, 'pdf'
, 'cumcount'
, or 'cdf'
) to use a unlike blazon of normalization. For a list of properties, come across Histogram Backdrop.
histogram(
plots into the axes specified past ax
,___)ax
instead of into the current axes (gca
). The option ax
can precede any of the input argument combinations in the previous syntaxes.
example
returns a h
= histogram(___)Histogram
object. Apply this to inspect and adjust the backdrop of the histogram. For a list of properties, see Histogram Properties.
Input Arguments
expand all
X
— Data to distribute amidst bins
vector | matrix | multidimensional assortment
Data to distribute among bins, specified as a vector, matrix, or multidimensional array. If X
is not a vector, and so histogram
treats it as a single column vector, X(:)
, and plots a single histogram.
histogram
ignores all NaN
and NaT
values. Similarly, histogram
ignores Inf
and -Inf
values, unless the bin edges explicitly specify Inf
or -Inf
as a bin edge. Although NaN
, NaT
, Inf
, and -Inf
values are typically not plotted, they are still included in normalization calculations that include the full number of data elements, such as 'probability'
.
Annotation
If X
contains integers of blazon int64
or uint64
that are larger than flintmax
, and so it is recommended that you explicitly specify the histogram bin edges. histogram
automatically bins the input data using double precision, which lacks integer precision for numbers greater than flintmax
.
Information Types: single
| double
| int8
| int16
| int32
| int64
| uint8
| uint16
| uint32
| uint64
| logical
| datetime
| elapsing
C
— Categorical information
categorical array
Categorical data, specified as a categorical array. histogram
does non plot undefined chiselled values. However, undefined categorical values are still included in normalization calculations that include the total number of data elements, such as 'probability'
.
Information Types: categorical
nbins
— Number of bins
positive integer
Number of bins, specified as a positive integer. If yous do not specify nbins
, then histogram
automatically calculates how many bins to use based on the values in Ten
.
Example: histogram(X,15)
creates a histogram with fifteen bins.
edges
— Bin edges
vector
Bin edges, specified as a vector. edges(1)
is the left edge of the first bin, and edges(end)
is the right edge of the last bin.
The value Ten(i)
is in the k
th bin if edges(k)
≤ 10(i)
< edges(k+1)
. The concluding bin also includes the right bin edge, so that it contains X(i)
if edges(end-1)
≤ X(i)
≤ edges(terminate)
.
For datetime and duration data, edges
must be a datetime or duration vector in monotonically increasing order.
Data Types: single
| double
| int8
| int16
| int32
| int64
| uint8
| uint16
| uint32
| uint64
| logical
| datetime
| duration
Notation
This option only applies to chiselled histograms.
Categories included in histogram, specified as a cell assortment of character vectors, categorical array, or string array.
-
If you lot specify an input chiselled array
C
, and so by default,histogram
plots a bar for each category inC
. In that case, useCategories
to specify a unique subset of the categories instead. -
If you specify bin counts, so
Categories
specifies the associated category names for the histogram.
Example: h = histogram(C,{'Large','Small'})
plots just the categorical data in the categories 'Large'
and 'Small'
.
Example: histogram('Categories',{'Yes','No','Maybe'},'BinCounts',[22 18 3])
plots a histogram that has three categories with the associated bin counts.
Example: h.Categories
queries the categories that are in histogram object h
.
Data Types: cell
| categorical
| string
counts
— Bin counts
vector
Bin counts, specified every bit a vector. Use this input to pass bin counts to histogram
when the bin counts calculation is performed separately and you do not want histogram
to exercise any data binning.
The length of counts
must exist equal to the number of bins.
-
For numeric histograms, the number of bins is
length(edges)-1
. -
For categorical histograms, the number of bins is equal to the number of categories.
Example: histogram('BinEdges',-2:two,'BinCounts',[5 8 fifteen nine])
Instance: histogram('Categories',{'Yes','No','Maybe'},'BinCounts',[22 eighteen iii])
ax
— Target axes
Axes
object | PolarAxes
object
Target axes, specified as an Axes
object or a PolarAxes
object. If you do non specify the axes and if the current axes are Cartesian axes, then the histogram
function uses the current axes (gca
). To plot into polar axes, specify the PolarAxes
object every bit the start input argument or employ the polarhistogram
function.
Name-Value Pair Arguments
Specify optional comma-separated pairs of Name,Value
arguments. Name
is the argument proper noun and Value
is the corresponding value. Name
must announced within quotes. Y'all can specify several name and value pair arguments in whatsoever order equally Name1,Value1,...,NameN,ValueN
.
Instance: histogram(X,'BinWidth',v)
The histogram backdrop listed hither are only a subset. For a complete list, encounter Histogram Backdrop.
Note
This option merely applies to histograms of categorical data.
Relative width of categorical bars, specified equally a scalar value in the range [0,ane]
. Utilize this property to control the separation of categorical bars within the histogram. The default value is 0.9
, which ways that the bar width is ninety% of the space from the previous bar to the next bar, with 5% of that space on each side.
If you set this property to 1
, so adjacent bars touch.
Case: 0.5
Data Types: unmarried
| double
| int8
| int16
| int32
| int64
| uint8
| uint16
| uint32
| uint64
Bin limits, specified as a two-element vector, [bmin,bmax]
. This selection plots a histogram using the values in the input array, X
, that fall betwixt bmin
and bmax
inclusive. That is, 10(Ten>=bmin & X<=bmax)
.
This selection does not utilise to histograms of chiselled data.
Example: histogram(X,'BinLimits',[1,10])
plots a histogram using only the values in Ten
that are between 1
and 10
inclusive.
Selection way for bin limits, specified as 'auto'
or 'manual'
. The default value is 'auto'
, and so that the bin limits automatically accommodate to the data.
If yous explicitly specify either BinLimits
or BinEdges
, then BinLimitsMode
is automatically set to 'manual'
. In that case, specify BinLimitsMode
as 'auto'
to rescale the bin limits to the information.
This selection does not apply to histograms of categorical data.
Binning algorithm, specified as one of the values in this table.
Value | Clarification |
---|---|
| The default |
| Scott'southward rule is optimal if the data is close to being commonly distributed. This dominion is appropriate for most other distributions, as well. Information technology uses a bin width of |
| The Freedman-Diaconis dominion is less sensitive to outliers in the data, and might be more suitable for data with heavy-tailed distributions. It uses a bin width of |
| The integer rule is useful with integer data, equally it creates a bin for each integer. It uses a bin width of ane and places bin edges halfway between integers. To avoid accidentally creating too many bins, you can use this rule to create a limit of 65536 bins (two16 ). If the data range is greater than 65536, then the integer rule uses wider bins instead. Note |
| Sturges' rule is pop due to its simplicity. It chooses the number of bins to be |
| The Foursquare Root rule is widely used in other software packages. It chooses the number of bins to be |
histogram
does not always choose the number of bins using these verbal formulas. Sometimes the number of bins is adjusted slightly so that the bin edges autumn on "nice" numbers.
For datetime information, the bin method can exist one of these units of fourth dimension:
'2d' | 'month' |
'minute' | 'quarter' |
'hour' | 'yr' |
'day' | 'decade' |
'week' | 'century' |
For elapsing data, the bin method can exist one of these units of time:
'second' | 'day' |
'minute' | 'year' |
'hr' |
If you specify BinMethod
with datetime or elapsing data, and so histogram
can use a maximum of 65,536 bins (or 216). If the specified bin elapsing requires more bins, and so histogram
uses a larger bin width corresponding to the maximum number of bins.
This option does not employ to histograms of categorical information.
Note
If you set the BinLimits
, NumBins
, BinEdges
, or BinWidth
property, then the BinMethod
property is gear up to 'transmission'
.
Instance: histogram(X,'BinMethod','integers')
creates a histogram with the bins centered on integers.
Width of bins, specified as a scalar. When you specify BinWidth
, and then histogram
tin apply a maximum of 65,536 bins (or 216 ). If instead the specified bin width requires more than bins, then histogram
uses a larger bin width respective to the maximum number of bins.
For datetime and duration data, the value of 'BinWidth'
can be a scalar elapsing or calendar elapsing.
This option does non apply to histograms of categorical data.
Example: histogram(Ten,'BinWidth',5)
uses bins with a width of five.
Category display order, specified as 'arise'
, 'descend'
, or 'data'
. With 'ascend'
or 'descend'
, the histogram displays with increasing or decreasing bar heights. The default 'data'
value uses the category order in the input data, C
.
This option only works with categorical data.
Histogram brandish style, specified equally either 'bar'
or 'stairs'
. Specify 'stairs'
to display a stairstep plot, which displays the outline of the histogram without filling the interior.
The default value of 'bar'
displays a histogram bar plot.
Example: histogram(X,'DisplayStyle','stairs')
plots the outline of the histogram.
EdgeAlpha
— Transparency of histogram bar edges
ane
(default) | scalar value between 0
and 1
inclusive
Transparency of histogram bar edges, specified as a scalar value between 0
and one
inclusive. A value of i
means fully opaque and 0
means completely transparent (invisible).
Example: histogram(10,'EdgeAlpha',0.5)
creates a histogram plot with semi-transparent bar edges.
EdgeColor
— Histogram edge color
[0 0 0]
or black (default) | 'none'
| 'auto'
| RGB triplet | hexadecimal color code | color name
Histogram edge colour, specified as one of these values:
-
'none'
— Edges are not fatigued. -
'auto'
— Colour of each edge is called automatically. -
RGB triplet, hexadecimal colour code, or colour name — Edges use the specified color.
RGB triplets and hexadecimal colour codes are useful for specifying custom colors.
-
An RGB triplet is a three-element row vector whose elements specify the intensities of the red, green, and blue components of the color. The intensities must be in the range
[0,1]
; for example,[0.4 0.6 0.7]
. -
A hexadecimal color code is a character vector or a cord scalar that starts with a hash symbol (
#
) followed by 3 or six hexadecimal digits, which can range from0
toF
. The values are non case sensitive. Thus, the color codes'#FF8800'
,'#ff8800'
,'#F80'
, and'#f80'
are equivalent.
Alternatively, yous tin can specify some mutual colors by name. This table lists the named color options, the equivalent RGB triplets, and hexadecimal color codes.
Colour Name Short Name RGB Triplet Hexadecimal Color Code Appearance 'cherry-red'
'r'
[1 0 0]
'#FF0000'
'greenish'
'g'
[0 i 0]
'#00FF00'
'blue'
'b'
[0 0 ane]
'#0000FF'
'cyan'
'c'
[0 one ane]
'#00FFFF'
'magenta'
'm'
[1 0 ane]
'#FF00FF'
'xanthous'
'y'
[one ane 0]
'#FFFF00'
'black'
'yard'
[0 0 0]
'#000000'
'white'
'west'
[i ane 1]
'#FFFFFF'
Here are the RGB triplets and hexadecimal color codes for the default colors MATLAB® uses in many types of plots.
RGB Triplet Hexadecimal Colour Lawmaking Appearance [0 0.4470 0.7410]
'#0072BD'
[0.8500 0.3250 0.0980]
'#D95319'
[0.9290 0.6940 0.1250]
'#EDB120'
[0.4940 0.1840 0.5560]
'#7E2F8E'
[0.4660 0.6740 0.1880]
'#77AC30'
[0.3010 0.7450 0.9330]
'#4DBEEE'
[0.6350 0.0780 0.1840]
'#A2142F'
-
Example: histogram(X,'EdgeColor','r')
creates a histogram plot with red bar edges.
FaceAlpha
— Transparency of histogram bars
0.6
(default) | scalar value between 0
and 1
inclusive
Transparency of histogram bars, specified as a scalar value betwixt 0
and 1
inclusive. histogram
uses the same transparency for all the bars of the histogram. A value of one
ways fully opaque and 0
means completely transparent (invisible).
Example: histogram(Ten,'FaceAlpha',1)
creates a histogram plot with fully opaque confined.
FaceColor
— Histogram bar colour
'machine'
(default) | 'none'
| RGB triplet | hexadecimal color code | colour proper noun
Histogram bar colour, specified every bit one of these values:
-
'none'
— Confined are not filled. -
'auto'
— Histogram bar color is chosen automatically (default). -
RGB triplet, hexadecimal colour code, or colour name — Bars are filled with the specified colour.
RGB triplets and hexadecimal color codes are useful for specifying custom colors.
-
An RGB triplet is a three-element row vector whose elements specify the intensities of the red, light-green, and blue components of the color. The intensities must be in the range
[0,one]
; for instance,[0.4 0.6 0.7]
. -
A hexadecimal colour code is a character vector or a string scalar that starts with a hash symbol (
#
) followed past three or half-dozen hexadecimal digits, which can range from0
toF
. The values are not case sensitive. Thus, the color codes'#FF8800'
,'#ff8800'
,'#F80'
, and'#f80'
are equivalent.
Alternatively, y'all can specify some mutual colors by name. This tabular array lists the named colour options, the equivalent RGB triplets, and hexadecimal color codes.
Color Proper name Short Name RGB Triplet Hexadecimal Color Lawmaking Appearance 'crimson'
'r'
[1 0 0]
'#FF0000'
'dark-green'
'thousand'
[0 1 0]
'#00FF00'
'blue'
'b'
[0 0 1]
'#0000FF'
'cyan'
'c'
[0 i 1]
'#00FFFF'
'magenta'
'm'
[1 0 1]
'#FF00FF'
'yellow'
'y'
[1 i 0]
'#FFFF00'
'black'
'grand'
[0 0 0]
'#000000'
'white'
'w'
[1 1 1]
'#FFFFFF'
Hither are the RGB triplets and hexadecimal color codes for the default colors MATLAB uses in many types of plots.
RGB Triplet Hexadecimal Colour Code Advent [0 0.4470 0.7410]
'#0072BD'
[0.8500 0.3250 0.0980]
'#D95319'
[0.9290 0.6940 0.1250]
'#EDB120'
[0.4940 0.1840 0.5560]
'#7E2F8E'
[0.4660 0.6740 0.1880]
'#77AC30'
[0.3010 0.7450 0.9330]
'#4DBEEE'
[0.6350 0.0780 0.1840]
'#A2142F'
-
If you specify DisplayStyle
as 'stairs'
, so histogram
does not use the FaceColor
property.
Case: histogram(X,'FaceColor','g')
creates a histogram plot with green bars.
Line manner, specified as one of the options listed in this table.
Line Style | Description | Resulting Line |
---|---|---|
'-' | Solid line |
|
'--' | Dashed line |
|
':' | Dotted line |
|
'-.' | Dash-dotted line |
|
'none' | No line | No line |
Width of bar outlines, specified as a positive value in bespeak units. I point equals 1/72 inch.
Example: 1.5
Data Types: single
| double
| int8
| int16
| int32
| int64
| uint8
| uint16
| uint32
| uint64
Type of normalization, specified as one of the values in this table. For each bin i
:
-
is the bin value.
-
is the number of elements in the bin.
-
is the width of the bin.
-
is the number of elements in the input information. This value can exist greater than the binned information if the data contains
NaN
,NaT
, or<undefined>
values, or if some of the information lies outside the bin limits.
Value | Bin Values | Notes |
---|---|---|
'count' (default) |
|
|
'countdensity' |
|
Note |
'cumcount' |
|
|
'probability' |
|
|
'pdf' |
|
Note |
'cdf' |
|
|
Example: histogram(X,'Normalization','pdf')
plots an approximate of the probability density office for Ten
.
Number of categories to display, specified every bit a scalar. Y'all tin modify the ordering of categories displayed in the histogram using the 'DisplayOrder'
pick.
This option just works with categorical information.
Orientation of bars, specified every bit 'vertical'
or 'horizontal'
.
Example: histogram(X,'Orientation','horizontal')
creates a histogram plot with horizontal confined.
Toggle summary display of data belonging to undisplayed categories, specified as 'on'
or 'off'
, or as numeric or logical one
(true
) or 0
(false
). A value of 'on'
is equivalent to true
, and 'off'
is equivalent to faux
. Thus, you can apply the value of this property as a logical value. The value is stored equally an on/off logical value of type matlab.lang.OnOffSwitchState
.
Prepare this option to 'on'
to display an additional bar in the histogram with the proper name 'Others'
. This extra bar counts all elements that do non belong to categories displayed in the histogram.
Y'all can modify the number of categories displayed in the histogram, too as their club, using the 'NumDisplayBins'
and 'DisplayOrder'
options.
This pick only works with categorical information.
Backdrop
Object Functions
Examples
collapse all
Histogram of Vector
Generate 10,000 random numbers and create a histogram. The histogram
function automatically chooses an advisable number of bins to cover the range of values in 10
and show the shape of the underlying distribution.
10 = randn(10000,1); h = histogram(x)
h = Histogram with properties: Data: [10000x1 double] Values: [two 2 1 half-dozen 7 17 29 57 86 133 193 271 331 421 540 613 ... ] NumBins: 37 BinEdges: [-3.8000 -iii.6000 -three.4000 -three.2000 -3 -2.8000 -2.6000 ... ] BinWidth: 0.2000 BinLimits: [-3.8000 3.6000] Normalization: 'count' FaceColor: 'automobile' EdgeColor: [0 0 0] Show all properties
When y'all specify an output argument to the histogram
function, information technology returns a histogram object. You can use this object to audit the backdrop of the histogram, such as the number of bins or the width of the bins.
Find the number of histogram bins.
Specify Number of Histogram Bins
Plot a histogram of 1,000 random numbers sorted into 25 equally spaced bins.
x = randn(thou,one); nbins = 25; h = histogram(x,nbins)
h = Histogram with backdrop: Data: [1000x1 double] Values: [1 iii 0 6 fourteen 19 31 54 74 80 92 122 104 115 88 lxxx 38 32 ... ] NumBins: 25 BinEdges: [-3.4000 -3.1200 -2.8400 -two.5600 -2.2800 -2 -1.7200 ... ] BinWidth: 0.2800 BinLimits: [-3.4000 3.6000] Normalization: 'count' FaceColor: 'motorcar' EdgeColor: [0 0 0] Prove all properties
Discover the bin counts.
counts = 1×25 1 3 0 half-dozen 14 xix 31 54 74 80 92 122 104 115 88 80 38 32 21 nine 5 5 5 0 two
Change Number of Histogram Bins
Generate 1,000 random numbers and create a histogram.
X = randn(1000,1); h = histogram(Ten)
h = Histogram with backdrop: Data: [1000x1 double] Values: [3 ane 2 xv 17 27 53 79 85 101 127 110 124 95 67 32 27 ... ] NumBins: 23 BinEdges: [-three.3000 -3.0000 -2.7000 -2.4000 -two.yard -i.8000 ... ] BinWidth: 0.3000 BinLimits: [-3.3000 3.6000] Normalization: 'count' FaceColor: 'automobile' EdgeColor: [0 0 0] Evidence all backdrop
Utilize the morebins
function to coarsely adjust the number of bins.
Nbins = morebins(h); Nbins = morebins(h)
Adjust the bins at a fine grain level by explicitly setting the number of bins.
Specify Bin Edges of Histogram
Generate 1,000 random numbers and create a histogram. Specify the bin edges as a vector with wide bins on the edges of the histogram to capture the outliers that do not satisfy . The kickoff vector element is the left edge of the first bin, and the last vector chemical element is the right border of the last bin.
ten = randn(thousand,one); edges = [-10 -2:0.25:ii 10]; h = histogram(ten,edges);
Specify the Normalization
holding as 'countdensity'
to flatten out the bins containing the outliers. At present, the surface area of each bin (rather than the height) represents the frequency of observations in that interval.
h.Normalization = 'countdensity';
Plot Categorical Histogram
Create a categorical vector that represents votes. The categories in the vector are 'yes'
, 'no'
, or 'undecided'
.
A = [0 0 1 1 ane 0 0 0 0 NaN NaN i 0 0 0 1 0 1 0 1 0 0 0 ane 1 one i]; C = categorical(A,[1 0 NaN],{'yes','no','undecided'})
C = 1x27 categorical Columns 1 through 9 no no aye yes yes no no no no Columns 10 through 16 undecided undecided aye no no no yes Columns 17 through 25 no yes no yes no no no yes yes Columns 26 through 27 yes yes
Plot a categorical histogram of the votes, using a relative bar width of 0.5
.
h = histogram(C,'BarWidth',0.5)
h = Histogram with properties: Information: [no no yes yep yes no no ... ] Values: [xi 14 2] NumDisplayBins: 3 Categories: {'yes' 'no' 'undecided'} DisplayOrder: 'data' Normalization: 'count' DisplayStyle: 'bar' FaceColor: 'auto' EdgeColor: [0 0 0] Bear witness all properties
Histogram with Specified Normalization
Generate 1,000 random numbers and create a histogram using the 'probability'
normalization.
x = randn(1000,i); h = histogram(x,'Normalization','probability')
h = Histogram with backdrop: Data: [1000x1 double] Values: [0.0030 one.0000e-03 0.0020 0.0150 0.0170 0.0270 0.0530 ... ] NumBins: 23 BinEdges: [-3.3000 -iii.0000 -2.7000 -2.4000 -2.1000 -one.8000 ... ] BinWidth: 0.3000 BinLimits: [-3.3000 3.6000] Normalization: 'probability' FaceColor: 'car' EdgeColor: [0 0 0] Show all properties
Compute the sum of the bar heights. With this normalization, the summit of each bar is equal to the probability of selecting an ascertainment within that bin interval, and the height of all of the bars sums to 1.
Plot Multiple Histograms
Generate two vectors of random numbers and plot a histogram for each vector in the same effigy.
ten = randn(2000,1); y = 1 + randn(5000,1); h1 = histogram(x); hold on h2 = histogram(y);
Since the sample size and bin width of the histograms are different, it is difficult to compare them. Normalize the histograms so that all of the bar heights add to 1, and use a uniform bin width.
h1.Normalization = 'probability'; h1.BinWidth = 0.25; h2.Normalization = 'probability'; h2.BinWidth = 0.25;
Adjust Histogram Properties
Generate 1,000 random numbers and create a histogram. Render the histogram object to adjust the properties of the histogram without recreating the entire plot.
x = randn(1000,i); h = histogram(10)
h = Histogram with backdrop: Data: [1000x1 double] Values: [3 1 ii xv 17 27 53 79 85 101 127 110 124 95 67 32 27 ... ] NumBins: 23 BinEdges: [-3.3000 -3.0000 -2.7000 -2.4000 -2.1000 -1.8000 ... ] BinWidth: 0.3000 BinLimits: [-3.3000 iii.6000] Normalization: 'count' FaceColor: 'auto' EdgeColor: [0 0 0] Show all properties
Specify exactly how many bins to use.
Specify the edges of the bins with a vector. The kickoff value in the vector is the left border of the first bin. The last value is the right edge of the last bin.
Alter the color of the histogram confined.
h.FaceColor = [0 0.5 0.v]; h.EdgeColor = 'r';
Determine Underlying Probability Distribution
Generate 5,000 unremarkably distributed random numbers with a hateful of five and a standard deviation of 2. Plot a histogram with Normalization
fix to 'pdf'
to produce an estimation of the probability density role.
x = 2*randn(5000,one) + 5; histogram(10,'Normalization','pdf')
In this example, the underlying distribution for the normally distributed data is known. Yous can, even so, employ the 'pdf'
histogram plot to make up one's mind the underlying probability distribution of the data past comparing it against a known probability density part.
The probability density function for a normal distribution with mean , standard deviation , and variance is
Overlay a plot of the probability density part for a normal distribution with a mean of v and a standard difference of two.
agree on y = -5:0.1:15; mu = v; sigma = 2; f = exp(-(y-mu).^2./(two*sigma^2))./(sigma*sqrt(ii*pi)); plot(y,f,'LineWidth',1.v)
Saving and Loading Histogram Objects
Utilize the savefig
function to salvage a histogram
figure.
histogram(randn(10)); savefig('histogram.fig'); close gcf
Utilize openfig
to load the histogram figure dorsum into MATLAB. openfig
too returns a handle to the effigy, h
.
h = openfig('histogram.fig');
Use the findobj
function to locate the right object handle from the effigy handle. This allows yous to continue manipulating the original histogram object used to generate the figure.
y = findobj(h,'type','histogram')
y = Histogram with properties: Data: [10x10 double] Values: [2 17 28 32 sixteen 3 2] NumBins: seven BinEdges: [-three -2 -1 0 i 2 3 4] BinWidth: ane BinLimits: [-3 four] Normalization: 'count' FaceColor: 'auto' EdgeColor: [0 0 0] Testify all properties
Tips
-
Histogram plots created using
histogram
have a context menu in plot edit mode that enables interactive manipulations in the figure window. For example, you lot tin can apply the context carte du jour to interactively modify the number of bins, align multiple histograms, or change the display order. -
When you add information tips to a histogram plot, they display the bin edges and bin count.
Extended Capabilities
Tall Arrays
Calculate with arrays that accept more rows than fit in memory.
This part supports tall arrays with the limitations:
-
Some input options are not supported. The immune options are:
-
'BinWidth'
-
'BinLimits'
-
'Normalization'
-
'DisplayStyle'
-
'BinMethod'
— The'auto'
and'scott'
bin methods are the same. The'fd'
bin method is not supported. -
'EdgeAlpha'
-
'EdgeColor'
-
'FaceAlpha'
-
'FaceColor'
-
'LineStyle'
-
'LineWidth'
-
'Orientation'
-
-
Additionally, in that location is a cap on the maximum number of bars. The default maximum is 100.
-
The
morebins
andfewerbins
methods are not supported. -
Editing backdrop of the histogram object that crave recomputing the bins is not supported.
For more information, see Tall Arrays for Out-of-Memory Information.
GPU Arrays
Accelerate code by running on a graphics processing unit (GPU) using Parallel Computing Toolbox™.
Usage notes and limitations:
-
This function accepts GPU arrays, but does not run on a GPU.
For more information, see Run MATLAB Functions on a GPU (Parallel Computing Toolbox).
Distributed Arrays
Partitioning big arrays beyond the combined memory of your cluster using Parallel Computing Toolbox™.
Usage notes and limitations:
-
This role operates on distributed arrays, just executes in the client MATLAB.
For more than data, see Run MATLAB Functions with Distributed Arrays (Parallel Computing Toolbox).
Introduced in R2014b
Source: https://ww2.mathworks.cn/help/matlab/ref/matlab.graphics.chart.primitive.histogram.html?lang=en
0 Response to "Read Image to Grayscale and Display It in a Histogram Matlab"
Post a Comment