%% Add Custom Properties
% Read data into a table. Then add properties to contain custom metadata.
% First, read measurements of humidity and air quality into a table. Display the first three rows.

T = readtable('indoors.csv');
head(T,3)

%
% Display the properties of the table. The properties object, T.Properties, stores metadata such as the names of the two dimensions of the table and the names of the table variables. All tables have such objects with the same properties. (Timetables also have similar objects that include additional, time-specific properties.)

T.Properties

%
% In addition, you can specify your own properties to store custom metadata. For example, use the addprop function to add properties to the table T for the instrument name, measurement precision, and the name of the source file. For properties that have one metadata value per variable, specify 'variable' as the property type. For properties that have one value that applies to the whole table, specify 'table'.

T = addprop(T,{'Instrument','Precision','SourceFile'},{'variable','variable','table'});
T.Properties

%
% When you create custom properties using addprop, the properties are empty. To store metadata values in the custom properties, assign them using dot syntax.

T.Properties.CustomProperties.Instrument = ["clock" "hygrometer" "air quality meter"];
T.Properties.CustomProperties.Precision = [NaN 0.5 0.1];
T.Properties.CustomProperties.SourceFile = 'indoors.csv';
T.Properties

%
% When you assign an array of text values to custom properties, the best practice is to use a string array, not a cell array of character vectors. If you use a cell array of character vectors, then there is no mechanism to prevent you from later assigning nontext values as elements of the cell array.
% Copyright 2018 The MathWorks, Inc.