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.

Print summary of table, timetable, or categorical array in MATLAB

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:

  1. Table
  2. Timetable
  3. Categorical Array/Vector

In this article, we shall see how to use the summary function on the above-mentioned MATLAB objects.

Similar Reads

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:...

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....

Summary of Time Tables

...

Summary of Categorical Arrays

...

1D Categorical Arrays

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....

Conclusion

...