MATLAB Programming Fundamentals - MathWorks

(やまだぃちぅ) #1

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 storm'
'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 storm'

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: []

9 Tables

Free download pdf