midpoints
midpoints(e)
Compute the midpoints of the bins with edges e
. The result is a vector/range of length length(e)  1
. Note: Julia does not ignore NaN
values in the computation.
Examples
In the Julia programming language, the function midpoints(e)
calculates the midpoints of the bins defined by the edges e
. The resulting vector or range has a length of length(e)  1
. It's important to note that Julia does not ignore NaN
values in the computation.

Calculate midpoints of bin edges:
julia> edges = [0, 2, 4, 6, 8]; julia> midpoints(edges) 4element Array{Float64,1}: 1.0 3.0 5.0 7.0
This example calculates the midpoints of the bins defined by the edges
[0, 2, 4, 6, 8]
. 
Compute midpoints using a range:
julia> edges = 0:2:8; julia> midpoints(edges) 4element StepRangeLen{Float64, Base.TwicePrecision{Float64}, Base.TwicePrecision{Float64}}: 1.0 3.0 5.0 7.0
It computes the midpoints using a range for the bin edges.
 Handling NaN values:
julia> edges = [0, 2, NaN, 6, 8]; julia> midpoints(edges) 3element Array{Float64,1}: NaN NaN 7.0
It shows that
NaN
values are not ignored in the computation, resulting inNaN
midpoints.
Common mistake example:
julia> edges = [0, 1, 2];
julia> midpoints(edges)
ERROR: DimensionMismatch("arrays could not be broadcast to a common size")
In this example, the length of the resulting vector would be 2
, but the provided edges have a length of 3
. The number of edges must be one more than the number of midpoints.
See Also
User Contributed Notes
Add a Note
The format of note supported is markdown, use triple backtick to start and end a code block.