Print summary of table, timetable, or categorical array in MATLAB
Last Updated :
24 Apr, 2025
MATLAB provides various ways to store and organize data such as tables, categorical arrays, arrays, timetables, vectors, etc. MATLAB deals with big data used for machine learning and other mathematical functions which require different organization of data. For small data it is efficient to take a look at the entire data and summarize it but, the same cannot be done when you are working with big data or binary data(.mat files).
For such situations, MATLAB provides the summary function which returns a brief summary of the data structure passed to it. It must be noted here that the summary function works only on three type of MATLAB objects:
- Table
- Timetable
- Categorical Array/Vector
In this article, we shall see how to use the summary function on the above-mentioned MATLAB objects.
Print summary of a table, timetable, or categorical array in MATLAB
The syntax of finding summary in MATLAB for any data that can be represented in a tabular form or categorical array or a datetime frame is given by:
s = summary(<object-name>, <optional-argument>)
Here, the object name could be either a table, timetable, or categorical array and the optional argument takes the dimension along which you need a summary. The dimension argument is optional and without it, summary returns the summary along all dimensions.
Summary of a Table
Summary function does not take any optional argument for tables or timetables therefore, we always get the summary of entire tables. Let us see the same with the help of examples.
First, we will create a table from random vectors and then will print out its summary using the summary() function.
Matlab
% Variables
emp_id = [12; 34; 37; 45; 65];
emp_names = {'Harry'; 'Sean'; 'Mark'; 'Maria'; 'Mia'};
salaries = [1500; 5400; 2300; 3000; 9000];
% creating table with above variables
rec = table(emp_id,emp_names,salaries);
Output:
>> rec
rec =
5x3 table
emp_id emp_names salaries
______ _________ ________
12 {'Harry'} 1500
34 {'Sean' } 5400
37 {'Mark' } 2300
45 {'Maria'} 3000
65 {'Mia' } 9000
We have created three column vectors above and using them, we created a table named rec. This table would look like this.
Now, we will print the summary of this table by typing the following command in the command space.
Matlab
% printing summary
summary(rec)
Output:
>> summary(rec)
Variables:
emp_id: 5x1 double
Values:
Min 12
Median 37
Max 65
emp_names: 5x1 cell array of character vectors
salaries: 5x1 double
Values:
Min 1500
Median 3000
Max 9000
Here, we can see that for the columns that contain numeric data, summary returns statistical values such as minimum, median, and maximum value whereas for the column that contains only text/character data, it simply return the size of the vector.
Summary of Time Tables
Summary function works in the same manner on time tables, as it works on ordinary tables. We pass the timetable object as an input and receive the summary.
In this example, we shall first create a timetable and then shall call the summary function on it.
Matlab
% variables for time table
dates = datetime({'2023-04-20'; '2023-04-21'; '2023-04-22'});
temp = [20; 23; 17];
% creating timetable
weather = timetable(dates,temp);
Output:
>> weather
weather =
3x1 timetable
dates temp
___________ ____
20-Apr-2023 20
21-Apr-2023 23
22-Apr-2023 17
Here, we have collected a data of temperatures on three dates. Then we created a timetable named weather. Now, we shall call the summary command in the command window to receive the summary of this timetable.
Matlab
Output:
>> summary(weather)
RowTimes:
dates: 3x1 datetime
Values:
Min 20-Apr-2023
Median 21-Apr-2023
Max 22-Apr-2023
TimeStep 24:00:00
Variables:
temp: 3x1 double
Values:
Min 17
Median 20
Max 23
Here we get similar output as of an ordinary table. Since the first column contains datetime data, we get the minimum, maximum and the median value along with a timestamp. For the second column, we receive summary containing the maximum, minimum and median value of the temperatures.
Summary of Categorical Arrays
We can get the summary of categorical array by simply passing it to the summary command. Here, we get two scenarios. First, when the array is a 1D vector and second when it is a 2D array. We shall see the same with the help of examples.
1D Categorical Arrays
When we call the summary function on a categorical array, it returns the category count of that array. See the following example.
Matlab
% creating a categorical array
cat = categorical({'red' 'bus' 'ship' 'bus' 'bike' 'car' 'red'});
% calling the summary function
summary(cat)
Output:
>> summary(cat)
bike bus car red ship
1 2 1 2 1
Firstly, we have created a categorical array and then, we called the summary function on it. The output will give us the category count along with the names of the categories.
2D Categorical Arrays
When we call the summary function on a 2D categorical array, it returns the category count along a particular dimension. The default dimension value is 1 i.e., column-wise. Let's see how this work.
Matlab
% 2D categorical array
cat = categorical({ 'red' 'bus';
'ship' 'bus';
'bike' 'car';
'red' 'ship'});
% calling the summary function
summary(cat)
Output:
>> summary(cat)
bike 1 0
bus 0 2
car 0 1
red 2 0
ship 1 1
Here, we have created a 2D categorical array with 5 categories. When we call the summary function on this array, it will display the column-wise category count, which is the default option.
Now, we can also retrieve the summary row-wise or along dimension 2. For doing so, we only need to pass the dimension value as 2. See the following code:
Matlab
% 2D categorical array
cat = categorical({ 'red' 'bus'; ...
'ship' 'bus'; ...
'bike' 'car'; ...
'red' 'ship'});
% rowwise summary
summary(cat,2)
Output:
>> summary(cat,2)
bike bus car red ship
0 1 0 1 0
0 1 0 0 1
1 0 1 0 0
0 0 0 1 1
This code will print the summary (in this case the category count) row-wise. We can clearly verify that all the category counts are given row-wise.
Conclusion
In this article, we explained how to print summary of a table, timetable, or categorical array/vector in MATLAB using the summary function. We explained summary of each object with the help of examples and also described various options available with the summary function.
Similar Reads
Categorical Arrays in MATLAB
In MATLAB, categorical is a data type which can assign values from a finite, discrete set of values. For example, consider there are three categories, 'positive', 'negative', and 'null' so, a categorical array, which is an array of categorical data type, will only take data which has values from the
3 min read
Create Array of Zeros in MATLAB
MATLAB generally stores its variables in matrix forms, also in array and vector form. Sometimes, we often need a matrix(or array or vector) of zero(s) for some specific operations. We can create a matrix of zero(s) manually or with the help of the in-built function of MATLAB. The in-built function t
5 min read
Count Occurrences of Categorical Array Elements By Category
Categorical arrays are arrays that stores data of categorical type in MATLAB. The categorical data is pre defined by a finite set of discrete values/categories from which any category can be selected multiple times. In this article, we shall learn how to count the occurrences of discrete categories
4 min read
How to extract numbers from cell array in MATLAB?
In this article, we are going to discuss the extraction of numbers from the cell array with the help of regexp(), str2double(), cat(), and isletter() functions. What is a Cell Array? A cell array is nothing but a data type having indexed data containers called cells, where each cell contains any typ
3 min read
Comparing Two Cell Arrays of Strings of Different Sizes in MATLAB
MATLAB is a high-performance language that is used for matrix manipulation, performing technical computations, graph plottings, etc. It stands for Matrix Laboratory. Cell Array: A cell Array in MATLAB is a data type that can store any type of data. Data is stored in cells in a cell array. It is init
2 min read
How to find sum of elements of an array in MATLAB?
This article will discuss the "Finding sum of elements of an array" in MATLAB that can be done using multiple approaches which are illustrated below. Â Using sum(A)Â This is used to return the sum of the elements of the array along the first array dimension whose size does not equal 1. It returns a ro
4 min read
MATLAB Find Exact String in Cell Array
Cell arrays in MATLAB store data of various data types as a cell. These cells could contain data of different types but belong to the same array. Now, this article is focused on finding an exact string in a cell array in MATLAB. This can be done easily by using a combination of two MATLAB functions,
2 min read
How to Write Data to Excel Spreadsheets in MATLAB?
MATLAB provides options to write a table, array, or matrix to Microsoft Excel spreadsheets. The function available to do so is the writetable () function. The general syntax for this function is: Syntax: writetable(<data>, <filename>, <optional_values>) Now, in the following sectio
3 min read
How to Find the Position of a Number in an Array in MATLAB?
Finding the position of a number in an array, which can be done using the find() function. The find() function is used to find the indices and values of the specified nonzero elements. Syntaxfind(X) Parameters: This function accepts a parameter. X: This is the specified number whose position is goin
1 min read
Define Import Options for Table in MATLAB
The import tool lets you import into a table or another type of data. Take into consideration reading data from the sample spreadsheet file patients.xls into MATLAB as a table. Open the file with the Import Tool, select the output format and date range, and save. After you click the Import Selection
3 min read