Geoscience Reference
In-Depth Information
and maximum values in
corg
. h e width of the bins
ewth
, as dei ned by the
bin edges, is equal to
vwth
. Binning can be performed using a
for
loop in
combination with an
if-then
construct. Values in
corg
that fall exactly on
an edge
e
are herein assigned to the higher bin. Values falling exactly on the
edge of the last bin are assigned to the last bin.
Gallery
3.1
for i = 1 : nbin
if i < nbin
corgb = corg(emin+(i-1)*ewth<=corg & emin+i*ewth>corg);
n(i) = length(corgb);
else
corgb = corg(emin+(i-1)*ewth<=corg & emin+i*ewth>=corg);
n(i) = length(corgb);
end
end
h e result of the binning is stored in the frequency distribution
n
, which we
can display with
n
which yields
n =
2 2 10 7 14 9 12 4
Instead of using the above script we can also use the functions
histcount
and
histogram
to determine the bin centers, edges and counts. Typing
histogram(corg)
displays a histogram with six classes, using an automatic binning algorithm.
h e algorithm returns bins with a uniform width, chosen to cover the range
of elements in
corg
and to reveal the underlying shape of the distribution.
h e MATLAB Help lists and explains various such methods for automatic
binning. h e function
histogram
also returns a structure array
h
h = histogram(corg);
which yields
h =
Histogram with properties:
Data: [60x1 double]
Values: [2 6 13 20 15 4]
NumBins: 6
BinEdges: [9 10 11 12 13 14 15]
BinWidth: 1
BinLimits: [9 15]
Normalization: 'count'