MATLAB Programming Fundamentals - MathWorks

(やまだぃちぅ) #1
ans=1×4 table
FirstName Height Weight BloodPressure
_________ ______ ______ _____________

Garcia 'Michael' 64 119 122 80

Perform an inner join on the two tables. Both tables use the last names of patients as row
names, and contain the first names as a table variable. Some patients in the two tables
have matching last names but different first names. To ensure that both last and first
names match, use the row names and FirstName as key variables. To specify the row
names as a key or grouping variable, use the name of the first dimension of the table. By
default, the name of the first dimension is 'Row'.

C = innerjoin(A,B,'Keys',{'Row','FirstName'})

C=2×5 table
FirstName Age Height Weight BloodPressure
_________ ___ ______ ______ _____________

Garcia 'Michael' 38 64 119 122 80
Wu 'Alice' 45 67 133 117 75

If you rename the first dimension of a table, then you can refer to the row names by that
name instead of using 'Row'. Perform the same inner join as above but use a different
name to refer to the row names.

Show the dimension names of A by accessing its Properties.DimensionNames
property.

A.Properties.DimensionNames

ans = 1x2 cell array
{'Row'} {'Variables'}

Change the name of the first dimension of the table by using its
Properties.DimensionNames property. Then use the new name as a key variable.

A.Properties.DimensionNames{1} = 'LastName';
A.Properties.DimensionNames

10 Timetables

Free download pdf