MATLAB Programming Fundamentals - MathWorks

(やまだぃちぅ) #1
Omit Duplicate Rows

To omit any rows in a table that are duplicated, use the unique function.

Tnew = unique(Tnew);
size(Tnew)

ans = 1×2

106 8

unique deleted two duplicate rows.

Delete Rows by Row Number

Delete rows 18, 20, and 21 from the table.

Tnew([18,20,21],:) = [];
size(Tnew)

ans = 1×2

103 8

The table contains information on 103 patients now.

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.

9 Tables

Free download pdf