ヒストグラムを計算
h = histc(n, data) h = histc(x, data) h = histc(.., normalization)
正の整数 (クラスの数)
クラスを定義する漸増ベクトル
(xには最低2つの要素があります)
ベクトル (解析対象のデータ)
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.
スカラー論理値 (デフォルト %T), setting the type of output
(see h).
この関数は,クラスxによりdataベクトルの
ヒストグラムを計算します.
xではなくクラスの数 nが指定された場合,等間隔で
x(1) = min(data) < x(2) = x(1) + dx < ... < x(n+1) = max(data)
(ただし, dx = (x(n+1)-x(1))/n)となるクラスが選択されます.
クラスはC1 = [x(1), x(2)] および Ci = ( x(i), x(i+1)]
(i >= 2)で定義されます.
Nmaxはdataの総数 (Nmax = length(data)),
NiはCiに含まれるdata要素の数,
Ciにおけるxのヒストグラムの値は,
"normalized"が選択された場合は
Ni/(Nmax (x(i+1)-x(i))) となり,
そうでない場合は単にNiとなります.
正規化が行われた際,ヒストグラムは以下を確認します:

x(1)<=min(data) および max(data) <= x(n+1) の場合
// ガウス乱数標本 d = rand(1, 10000, 'normal'); h = histc(20, d, normalization=%f); sum(h) // = 10000 // グラフィック表現を示すためにhistplotを使用 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); | ![]() | ![]() |

d = grand(1000,1,"bin", 6, 0.5); c = linspace(-0.5,6.5,8); clf() subplot(2,1,1) h = histc(c, d); histplot(c, d, style=2); xtitle(_("Normalized histogram")) subplot(2,1,2) h = histc(c, d, normalization=%f); histplot(c, d, normalization=%f, style=5); xtitle(_("Non normalized histogram")) | ![]() | ![]() |

lambda = 2; X = grand(100000,1,"exp", 1/lambda); Xmax = max(X); h = histc(40, X); clf() 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")]); | ![]() | ![]() |

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"); | ![]() | ![]() |

| バージョン | 記述 |
| 5.5.0 | Introduction |