tabulate(x) displays a frequency table of the
data in the vector x. For each unique value in x,
the tabulate function shows the number of instances and percentage of
that value in x. See tbl.
Create a frequency table for a vector of positive integers. By default, if a vector x contains only positive integers, then tabulate returns 0 counts for the integers between 1 and max(x) that do not appear in x. To avoid this behavior, convert the vector x to a categorical vector before calling tabulate.
Load the patients data set. Display the first five entries of the Height variable. Each value indicates the height, in inches, of a patient.
load patients
Height(1:5)
ans = 5×1
71
69
64
67
64
Create a frequency table that shows, in its second and third columns, the number and percentage of patients in the data set that have a particular height. Display the first five entries and the last five entries of the matrix that tabulate returns. tbl contains one row for each height between 1 and 72 inches, where 72 is the maximum height value in Height.
Generate a frequency table that shows Count and Percent values only for heights that appear in the Height variable. Convert Height to a categorical variable, and then call the tabulate function.
Create a frequency table from a character array by using tabulate. Convert the resulting cell array to a table array, and visualize the results.
Load the carsmall data set. Tabulate the data in the Origin variable, which shows the country of origin of each car in the data set. Convert the resulting cell array tbl to a table array t. Change the Value column to a categorical vector.
Create a frequency table from a numeric vector with NaN values.
Load the carsmall data set. The MPG variable contains the miles per gallon measurement of 100 cars. For six of the cars, the MPG value is missing (NaN).
The frequency table displays data only for the 94 cars with numeric MPG values. tabulate calculates the percentage of each MPG value in this subset of cars, not the entire set of 100 cars.
x — Input data numeric vector | logical vector | categorical vector | character array | string array | cell array of character vectors
Input data, specified as a numeric vector, logical vector, categorical vector,
character array, string array, or cell array of character vectors.
If x is a numeric vector, then tbl is
a numeric matrix.
If x is a logical vector, categorical vector, character
array, string array, or cell array of character vectors, then
tbl is a cell array.
Note
If the elements of x are positive integers, then the
frequency table includes 0 counts for the integers between
1 and max(x) that do not appear in
x. For an example, see Tabulate Positive Integer Vector.
Data Types: single | double | logical | categorical | char | string | cell
You can also select a web site from the following list:
How to Get Best Site Performance
Select the China site (in Chinese or English) for best site performance. Other MathWorks country sites are not optimized for visits from your location.