Вопрос

The following data display the number of errors per book for 20 publisher

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

Now i want to compute a frequency table with a class of interval of size 2 and relative frequency by using MATLAB.

I can make a frequency table by the command tabulate(x) but do not finding any reference that clarify how to compute a frequency table with a class of interval of size 2.

Это было полезно?

Решение

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%
Лицензировано под: CC-BY-SA с атрибуция
Не связан с StackOverflow
scroll top