Add and Delete Table Rows
This example shows how to add and delete rows in a table. You can also edit tables using
the Variables Editor.
Load Sample Data
Load the sample patients data and create a table, T.
load patients
T = table(LastName,Gender,Age,Height,Weight,Smoker,Systolic,Diastolic);
size(T)
ans = 1×2
100 8
The table, T, has 100 rows and eight variables (columns).
Add Rows by Concatenation
Read data on more patients from a comma-delimited file, morePatients.csv, into a
table, T2. Then, append the rows from T2 to the end of the table, T.
T2 = readtable('morePatients.csv');
Tnew = [T;T2];
size(Tnew)
ans = 1×2
104 8
The table Tnew has 104 rows. In order to vertically concatenate two tables, both tables
must have the same number of variables, with the same variable names. If the variable
names are different, you can directly assign new rows in a table to rows from another
table. For example, T(end+1:end+4,:) = T2.
Add Rows from Cell Array
To append new rows stored in a cell array, vertically concatenate the cell array onto the
end of the table. You can concatenate directly from a cell array when it has the right
9 Tables