addprop
Add custom properties to table or timetable
Description
T = addprop(
adds properties that contain custom metadata to the table or timetable T
,propertyNames
,propertyTypes
)T
.
The input argument propertyNames
specifies the names of the properties.
For each custom property, propertyTypes
specifies whether the metadata
values contained in the property apply to T
as a whole, or to the
variables of T
.
After you add properties using addprop
, you can assign metadata
values to the properties using dot syntax.
Examples
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)
Time Humidity AirQuality ___________________ ________ __________ 2015-11-15 00:00:24 36 80 2015-11-15 01:13:35 36 80 2015-11-15 02:26:47 37 79
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
ans = TableProperties with properties: Description: '' UserData: [] DimensionNames: {'Row' 'Variables'} VariableNames: {'Time' 'Humidity' 'AirQuality'} VariableTypes: ["datetime" "double" "double"] VariableDescriptions: {} VariableUnits: {} VariableContinuity: [] RowNames: {} CustomProperties: No custom properties are set. Use addprop and rmprop to modify CustomProperties.
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
ans = TableProperties with properties: Description: '' UserData: [] DimensionNames: {'Row' 'Variables'} VariableNames: {'Time' 'Humidity' 'AirQuality'} VariableTypes: ["datetime" "double" "double"] VariableDescriptions: {} VariableUnits: {} VariableContinuity: [] RowNames: {} Custom Properties (access using t.Properties.CustomProperties.<name>): SourceFile: [] Instrument: [] Precision: []
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
ans = TableProperties with properties: Description: '' UserData: [] DimensionNames: {'Row' 'Variables'} VariableNames: {'Time' 'Humidity' 'AirQuality'} VariableTypes: ["datetime" "double" "double"] VariableDescriptions: {} VariableUnits: {} VariableContinuity: [] RowNames: {} Custom Properties (access using t.Properties.CustomProperties.<name>): SourceFile: 'indoors.csv' Instrument: ["clock" "hygrometer" "air quality meter"] Precision: [NaN 0.5000 0.1000]
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.
Input Arguments
T
— Input table
table | timetable
Input table, specified as a table or timetable.
propertyNames
— Names of custom properties
character vector | cell array of character vectors | string array
Names of the custom properties, specified as a character vector, cell array of character vectors, or string array.
propertyTypes
— Property types
character vector | cell array of character vectors | string array
Property types, specified as a character vector, cell array of character vectors, or
string array. For each property name specified by propertyNames
,
specify the corresponding property type as either 'table'
or
'variable'
. The number of property types must equal the number of
property names.
The table describes the two property types.
Property Type | Description |
---|---|
| The property contains a single value of arbitrary size. The value applies as metadata to the table or timetable as a whole. |
| The property contains an array that has one value for each variable in the table or timetable. The values are metadata for the variables. The number of values in the array must match the number of variables. The values stored by the property are synchronized with the variables. They respond when you take one of these actions:
|
Version History
Introduced in R2018b
Comando de MATLAB
Ha hecho clic en un enlace que corresponde a este comando de MATLAB:
Ejecute el comando introduciéndolo en la ventana de comandos de MATLAB. Los navegadores web no admiten comandos de MATLAB.
Select a Web Site
Choose a web site to get translated content where available and see local events and offers. Based on your location, we recommend that you select: .
You can also select a web site from the following list:
How to Get Best Site Performance
Select the China site (in Chinese or English) for best site performance. Other MathWorks country sites are not optimized for visits from your location.
Americas
- América Latina (Español)
- Canada (English)
- United States (English)
Europe
- Belgium (English)
- Denmark (English)
- Deutschland (Deutsch)
- España (Español)
- Finland (English)
- France (Français)
- Ireland (English)
- Italia (Italiano)
- Luxembourg (English)
- Netherlands (English)
- Norway (English)
- Österreich (Deutsch)
- Portugal (English)
- Sweden (English)
- Switzerland
- United Kingdom (English)