Create and Work with Tables
This example shows how to create a table from workspace variables, work with table
data, and write tables to files for later use. table is a data type for collecting
heterogeneous data and metadata properties such as variable names, row names,
descriptions, and variable units, in a single container.
Tables are suitable for column-oriented or tabular data that are often stored as columns in
a text file or in a spreadsheet. Each variable in a table can have a different data type, but
must have the same number of rows. However, variables in a table are not restricted to
column vectors. For example, a table variable can contain a matrix with multiple columns
as long as it has the same number of rows as the other table variables. A typical use for a
table is to store experimental data, where rows represent different observations and
columns represent different measured variables.
Tables are convenient containers for collecting and organizing related data variables and
for viewing and summarizing data. For example, you can extract variables to perform
calculations and conveniently add the results as new table variables. When you finish your
calculations, write the table to a file to save your results.
Create and View Table
Create a table from workspace variables and view it. Alternatively, use the Import Tool or
the readtable function to create a table from a spreadsheet or a text file. When you
import data from a file using these functions, each column becomes a table variable.
Load sample data for 100 patients from the patients MAT-file to workspace variables.
load patients
whos
Name Size Bytes Class Attributes
Age 100x1 800 double
Diastolic 100x1 800 double
Gender 100x1 12212 cell
Height 100x1 800 double
LastName 100x1 12416 cell
Location 100x1 15008 cell
SelfAssessedHealthStatus 100x1 12340 cell
Smoker 100x1 100 logical
Systolic 100x1 800 double
Weight 100x1 800 double
9 Tables