0

以下数据显示了 20 个出版商每本书的错误数

2, 5, 2, 8, 2, 3, 5, 6, 1, 0, 2, 0, 1, 5, 0, 0, 4, 5, 1, 2

现在我想计算一个频率表,其间隔类别为 2,相对频率使用MATLAB.

我可以通过命令制作频率表,tabulate(x)但没有找到任何说明如何使用class of interval of size 2.

4

1 回答 1

3

You can use histc, which allows to specify the edges of the histogram bins. It doesn't compute relative frequencies or print a table though, you have to do this yourself:

% error data
e = [2, 5, 2, 8, 2, 3, 5, 6, 1, 0, 2, 0, 1, 5, 0, 0, 4, 5, 1, 2];

% bin edges
be = 0 :2: ceil(max(e) / 2) * 2;

% absolute frequencies
af = histc(e, be);

% relative frequencies
rf = af / sum(af);

% print table
fprintf('  Value  Count  Percent\n')
fprintf('  %d-%d\t %d\t    %5.2f%%\n', [be; be + 1; af; rf * 100])

The result is:

  Value  Count  Percent
  0-1    7      35.00%
  2-3    6      30.00%
  4-5    5      25.00%
  6-7    1       5.00%
  8-9    1       5.00%
于 2013-10-15T17:45:01.027 回答