A = table(categorical({'M';'M';'F';'M';'F'}),...
[27;52;31;46;35],[74;68;64;61;64],...'VariableNames',{'Gender''Age''Height'},...'RowNames',{'Ted''Fred''Betty''Bob''Judy'})
A=5×3 table
Gender Age Height
______ ___ ______
Ted M 27 74
Fred M 52 68
Betty F 31 64
Bob M 46 61
Judy F 35 64
创建一个与 A 具有共有行的表 B。
B = table(categorical({'F';'M';'F';'F'}),...
[31;47;35;23],[64;68;62;58],...'VariableNames',{'Gender''Age''Height'},...'RowNames',{'Meg''Joe''Beth''Amy'})
B=4×3 table
Gender Age Height
______ ___ ______
Meg F 31 64
Joe M 47 68
Beth F 35 62
Amy F 23 58
查找 A 与 B 以及索引向量 ia 和 ib 的共有行,使得 C = A(ia,:) 并且 C = B(ib,:)。
[C,ia,ib] = intersect(A,B)
C=1×3 table
Gender Age Height
______ ___ ______
Betty F 31 64
ia = 3
ib = 1
值相同而名称不同的两行将被视为相等。因此,我们发现 Betty A(3,:) 和 Meg, B(1,:) 的性别、年龄及身高都相同。
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.