Advantages of Using Tables
Conveniently Store Mixed-Type Data in Single Container
You can use the table data type to collect mixed-type data and metadata properties, such
as variable name, row names, descriptions, and variable units, in a single container.
Tables are suitable for column-oriented or tabular data that is often stored as columns in
a text file or in a spreadsheet. For example, you can use a table to store experimental
data, with rows representing different observations and columns representing different
measured variables.
Tables consist of rows and column-oriented variables. Each variable in a table can have a
different data type and a different size, but each variable must have the same number of
rows.
For example, load sample patients data.
load patients
Then, combine the workspace variables, Systolic and Diastolic into a single
BloodPressure variable and convert the workspace variable, Gender, from a cell array
of character vectors to a categorical array.
BloodPressure = [Systolic Diastolic];
Gender = categorical(Gender);
whos('Gender','Age','Smoker','BloodPressure')
Name Size Bytes Class Attributes
Age 100x1 800 double
BloodPressure 100x2 1600 double
Gender 100x1 346 categorical
Smoker 100x1 100 logical
The variables Age, BloodPressure, Gender, and Smoker have varying data types and
are candidates to store in a table since they all have the same number of rows, 100.
Now, create a table from the variables and display the first five rows.
T = table(Gender,Age,Smoker,BloodPressure);
T(1:5,:)
9 Tables