Delete Rows by Row Name
First, specify the variable of identifiers, LastName, as row names. Then, delete the variable,
LastName, from Tnew. Finally, use the row name to index and delete rows.
Tnew.Properties.RowNames = Tnew.LastName;
Tnew.LastName = [];
Tnew('Smith',:) = [];
size(Tnew)
ans = 1×2
102
7
The table now has one less row and one less variable.
Search for Rows to Delete
You also can search for observations in the table. For example, delete rows for any patients under the
age of 30.
toDelete = Tnew.Age < 30;
Tnew(toDelete,:) = [];
size(Tnew)
ans = 1×2
85
7
The table now has 17 fewer rows.
See Also
table | readtable | array2table | cell2table | struct2table
Related Examples
•
“Add, Delete, and Rearrange Table Variables” on page 9-12
•
“Clean Messy and Missing Data in Tables” on page 9-19
Add and Delete Table Rows
9-11
First, specify the variable of identifiers, LastName, as row names. Then, delete the variable,
LastName, from Tnew. Finally, use the row name to index and delete rows.
Tnew.Properties.RowNames = Tnew.LastName;
Tnew.LastName = [];
Tnew('Smith',:) = [];
size(Tnew)
ans = 1×2
102
7
The table now has one less row and one less variable.
Search for Rows to Delete
You also can search for observations in the table. For example, delete rows for any patients under the
age of 30.
toDelete = Tnew.Age < 30;
Tnew(toDelete,:) = [];
size(Tnew)
ans = 1×2
85
7
The table now has 17 fewer rows.
See Also
table | readtable | array2table | cell2table | struct2table
Related Examples
•
“Add, Delete, and Rearrange Table Variables” on page 9-12
•
“Clean Messy and Missing Data in Tables” on page 9-19
Add and Delete Table Rows
9-11
