Name = {'Fred';'Betty';'Bob';'George';'Jane'};
Age = [38;43;38;40;38];
Height = [71;69;64;67;64];
Weight = [176;163;131;185;131];
A = table(Age,Height,Weight,'RowNames',Name)
A=5×3 table
Age Height Weight
___ ______ ______
Fred 38 71 176
Betty 43 69 163
Bob 38 64 131
George 40 67 185
Jane 38 64 131
查找 A 的唯一行。unique 按排序顺序(依次按第一个变量 Age 和第二个变量 Height 排序)返回 A 的行。
C = unique(A)
C=4×3 table
Age Height Weight
___ ______ ______
Bob 38 64 131
Fred 38 71 176
George 40 67 185
Betty 43 69 163
在第一个变量 Age 中查找具有唯一值的表行。如果只希望一个表变量包含唯一值,可以使用 unique 返回的索引从表中提取这些行。
[C,ia] = unique(A.Age);
B = A(ia,:)
B=3×3 table
Age Height Weight
___ ______ ______
Fred 38 71 176
George 40 67 185
Betty 43 69 163
You can also select a web site from the following list:
How to Get Best Site Performance
Select the China site (in Chinese or English) for best site performance. Other MathWorks country sites are not optimized for visits from your location.