| Products & Services | Solutions | Academia | Support | User Community | Company |
| Download Product Updates | | | Get Pricing | | | Trial Software |
| Documentation → MATLAB |
| Contents | Index |
| Learn more about MATLAB |
n = histc(x,edges)
n = histc(x,edges,dim)
[n,bin] = histc(...)
n = histc(x,edges) counts the number of values in vector x that fall between the elements in the edges vector (which must contain monotonically nondecreasing values). n is a length(edges) vector containing these counts. No elements of x can be complex.
n(k) counts the value x(i) if edges(k) <= x(i) < edges(k+1). The last bin counts any values of x that match edges(end). Values outside the values in edges are not counted. Use -inf and inf in edges to include all non-NaN values.
For matrices, histc(x,edges) returns a matrix of column histogram counts. For N-D arrays, histc(x,edges) operates along the first nonsingleton dimension.
n = histc(x,edges,dim) operates along the dimension dim.
[n,bin] = histc(...) also returns an index matrix bin. If x is a vector, n(k) = sum(bin==k). bin is zero for out of range values. If x is an M-by-N matrix, then
for j=1:N, n(k,j) = sum(bin(:,j)==k); end
To plot the histogram, use the bar command.
Generate a cumulative histogram of a distribution.
Consider the following distribution:
x = -2.9:0.1:2.9; y = randn(10000,1); figure(1), hist(y,x)

Calculate number of elements in each bin
n_elements = histc(y,x);
Calculate the cumulative sum of these elements using cumsum
c_elements = cumsum(n_elements)
Plot the cumulative histogram
figure(2),bar(x,c_elements)

Specialized Plotting for related functions
![]() | hist | hold | ![]() |

Includes the most popular MATLAB recorded presentations with Q&A sessions led by MATLAB experts.
| © 1984-2009- The MathWorks, Inc. - Site Help - Patents - Trademarks - Privacy Policy - Preventing Piracy - RSS |