%% Modify Units, Descriptions, and Table Variable Names
% This example shows how to access and modify table properties for variable units, descriptions and names. You also can edit these property values using the Variables Editor.
%% Load Sample Data
% Load the sample patients data and create a table.

load patients
BloodPressure = [Systolic Diastolic];

T = table(Gender,Age,Height,Weight,Smoker,BloodPressure);

%
% Display the first five rows of the table, T.

T(1:5,:)

% T has 100 rows and 6 variables.
%
%% Add Variable Units
% Specify units for each variable in the table by modifying the table property, VariableUnits. Specify the variable units as a cell array of character vectors.

T.Properties.VariableUnits = {'' 'Yrs' 'In' 'Lbs' '' ''};

% An individual empty character vector within the cell array indicates that the corresponding variable does not have units.
%
%% Add a Variable Description for a Single Variable
% Add a variable description for the variable, BloodPressure. Assign a single character vector to the element of the cell array containing the description for BloodPressure.

T.Properties.VariableDescriptions{'BloodPressure'} = 'Systolic/Diastolic';

% You can use the variable name, 'BloodPressure', or the numeric index of the variable, 6, to index into the cell array of character vectors containing the variable descriptions.
%
%% Summarize the Table
% View the data type, description, units, and other descriptive statistics for each variable by using summary to summarize the table.

summary(T)

% The BloodPressure variable has a description and the Age, Height, Weight, and BloodPressure variables have units.
%
%% Change a Variable Name
% Change the variable name for the first variable from Gender to Sex.

T.Properties.VariableNames{'Gender'} = 'Sex';

%
% Display the first five rows of the table, T.

T(1:5,:)

% In addition to properties for variable units, descriptions and names, there are table properties for row and dimension names, a table description, and user data.
% Copyright 2012 The MathWorks, Inc.