%% Specify Row Names
% Specify row names for a table. Tables do not have to have row names, but if you specify them, then you can index into a table by row name. You also can access the set of row names using the name of the first dimension of a table.
% Create arrays containing patient data.

LastName = {'Sanchez';'Johnson';'Lee';'Diaz';'Brown'};
Age = [38;43;38;40;49];
Height = [71;69;64;67;64];
Weight = [176;163;131;133;119];

%
% Create a table containing the arrays. Specify LastName as the source of row names for the table. The table has only three variables. The row names are not a table variable, but instead a property of the table.

T = table(Age,Weight,Height,'RowNames',LastName)

%
% Since the rows have row names, you can index into the rows of T by name.

T('Lee',:)

%
% To specify multiple rows, use a cell array.

T({'Lee','Brown'},:)

%
% To access all the row names of T as a cell array, use the syntax T.Row. By default, Row is the name of the first dimension of a table.

T.Row

%
% Change the name of the first dimension. If you change the name, then you can access the row names using the new name.

T.Properties.DimensionNames{1} = 'LastNames';
T.LastNames

% Copyright 2012 The MathWorks, Inc.