%% Table Summary Including Custom Properties
% Starting in R2018b, you can add custom properties to tables and timetables. If you add custom properties, then the summary of a table or timetable includes those properties.
% First, create a table and add values to some of its predefined properties.

load patients
BloodPressure = [Systolic Diastolic];
T = table(Gender,Age,Smoker,BloodPressure,'RowNames',LastName);
T.Properties.Description = 'Simulated patient data';
T.Properties.VariableUnits =  {''  'Yrs' ''  'mm Hg'};
T.Properties.VariableDescriptions{4} = 'Systolic/Diastolic';

%
% Add custom properties using the addprop function. For each custom property, specify a name. Also, specify whether the value of each custom property stores metadata that applies to the table or to individual table variables.

T = addprop(T,{'SourceFile','DataOrigin'},{'table','variable'});

%
% Store metadata values in the custom properties.

T.Properties.CustomProperties.SourceFile = 'patients.mat';
T.Properties.CustomProperties.DataOrigin = {'census','census','self report','blood pressure reading'};

%
% Print a summary of the table. Aside from T.Properties.Description, the summary function does not display properties that apply to the table as a whole. So, it does not display the value of T.Properties.CustomProperties.SourceFile. However, summary does display properties that apply to table variables. For each variable, summary displays the corresponding value from T.Properties.CustomProperties.DataOrigin.

summary(T)

%
% Return the summary as a structure. Each field has a structure corresponding to one of the table variables.

s = summary(T)

%
% The structure s.Age stores the summary for the Age variable.

s.Age

%
% The s.Age.CustomProperties structure stores the corresponding value from the T.Properties.CustomProperties.DataOrigin property.

s.Age.CustomProperties

% Copyright 2018 The MathWorks, Inc.