Scilab Home page | Wiki | Bug tracker | Forge | Mailing list archives | ATOMS | File exchange
Please login or create an account
Change language to: English - Français - Português - 日本語 -
Справка Scilab >> Statistics > Descriptive Statistics > histc


computes an histogram


h = histc(n, data)
h = histc(x, data)
h = histc(.., normalization)



positive integer (number of classes)


increasing vector defining the classes (x may have at least 2 components)


vector (data to be analysed)


  • If normalization is %T: Probability densities on the bins defined by n or x, such that the bins areas are proportionnal to their populations.

  • If normalization is %F: Numbers of elements in the bins.


scalar boolean (default = %T), setting the type of output (see h).


This function computes a histogram of the data vector using the classes x. When the number n of classes is provided instead of x, the classes are chosen equally spaced and x(1) = min(data) < x(2) = x(1) + dx < ... < x(n+1) = max(data) with dx = (x(n+1)-x(1))/n.

The classes are defined by C1 = [x(1), x(2)] and Ci = ( x(i), x(i+1)] for i >= 2. Noting Nmax the total number of data (Nmax = length(data)) and Ni the number of data components falling in Ci, the value of the histogram for x in Ci is equal to Ni/(Nmax (x(i+1)-x(i))) when "normalized" is selected and else, simply equal to Ni. When normalization occurs the histogram verifies:


when x(1)<=min(data) and max(data) <= x(n+1)


  • Example #1: variations around a histogram of a gaussian random sample
    // The gaussian random sample
    d = rand(1, 10000, 'normal');
    h = histc(20, d, normalization=%f);
    sum(h)   // = 10000
    // We use histplot to show a graphic representation
    clf(); histplot(20, d, normalization=%f);
    // Normalized histogram (probability density)
    h = histc(20, d);
    dx = (max(d)-min(d))/20;  sum(h)*dx   // = 1
    clf(); histplot(20, d);
  • Example #2: histogram of a binomial (B(6,0.5)) random sample
    d = grand(1000,1,"bin", 6, 0.5);
    c = linspace(-0.5,6.5,8);
    h = histc(c, d);
    histplot(c, d, style=2);
    xtitle(_("Normalized histogram"))
    h = histc(c, d, normalization=%f);
    histplot(c, d, normalization=%f, style=5);
    xtitle(_("Non normalized histogram"))
  • Example #3: histogram of an exponential random sample
    lambda = 2;
    X = grand(100000,1,"exp", 1/lambda);
    Xmax = max(X);
    h = histc(40, X);
    histplot(40, X, style=2);
    x = linspace(0, max(Xmax), 100)';
    plot2d(x, lambda*exp(-lambda*x), strf="000", style=5)
    legend([_("exponential random sample histogram") _("exact density curve")]);
  • Example #4: the frequency polygon chart and the histogram of a gaussian random sample
    n = 10;
    data = rand(1, 1000, "normal");
    h = histc(n, data);
    clf(), histplot(n, data, style=12, polygon=%t);
    legend([_("normalized histogram") _("frequency polygon chart")], "lower_caption");

See also

  • histplot — plot a histogram
  • hist3d — трёхмерное представление гистограммы
  • plot2d — 2D plot
  • dsearch — поиск в упорядоченных наборах


5.5.0 Introduction
Scilab Enterprises
Copyright (c) 2011-2017 (Scilab Enterprises)
Copyright (c) 1989-2012 (INRIA)
Copyright (c) 1989-2007 (ENPC)
with contributors
Last updated:
Thu Feb 14 15:05:02 CET 2019