Add Custom Properties to Tables and Timetables
This example shows how to add custom properties to tables and timetables, set and access their
values, and remove them.
All tables and timetables have properties that contain metadata about them or their variables. You
can access these properties through the T.Properties object, where T is the name of the table or
timetable. For example, T.Properties.VariableNames returns a cell array containing the names
of the variables of T.
The properties you access through T.Properties are part of the definitions of the table and
timetable data types. You cannot add or remove these predefined properties. But starting in
R2018b, you can add and remove your own custom properties, by modifying the
T.Properties.CustomProperties object of a table or timetable.
Add Properties
Read power outage data into a table. Sort it using the first variable that contains dates and times,
OutageTime. Then display the first three rows.
T = readtable('outages.csv');
T = sortrows(T,'OutageTime');
head(T,3)
ans=3×6 table
Region
OutageTime
Loss
Customers
RestorationTime
Cause
_____________
________________
______
__________
________________
____________
{'SouthWest'}
2002-02-01 12:18
458.98
1.8202e+06
2002-02-07 16:50
{'winter sto
{'MidWest' }
2002-03-05 17:53
96.563
2.8666e+05
2002-03-10 14:41
{'wind'
{'MidWest' }
2002-03-16 06:18
186.44
2.1275e+05
2002-03-18 23:23
{'severe sto
Display its properties. These are the properties that all tables have in common. Note that there is also
a CustomProperties object, but that by default it has no properties.
T.Properties
ans =
TableProperties with properties:
Description: ''
UserData: []
DimensionNames: {'Row' 'Variables'}
VariableNames: {1x6 cell}
VariableDescriptions: {}
VariableUnits: {}
VariableContinuity: []
RowNames: {}
CustomProperties: No custom properties are set.
Use addprop and rmprop to modify CustomProperties.
To add custom properties, use the addprop function. Specify the names of the properties. For each
property, also specify whether it has metadata for the whole table (similar to the Description
property) or for its variables (similar to the VariableNames property). If the property has variable
metadata, then its value must be a vector whose length is equal to the number of variables.
Add Custom Properties to Tables and Timetables
9-27
Précédent

- 371/1450

Suivant