addprop
说明
T = addprop(
将包含自定义元数据的属性添加到表或时间表 T
,propertyNames
,propertyTypes
)T
。输入参数 propertyNames
指定属性的名称。对于每个自定义属性,propertyTypes
指定是将属性中包含的元数据值整体应用于 T
,还是应用于 T
的变量。
使用 addprop
添加属性后,可以使用圆点语法将元数据值赋给属性。
示例
添加自定义属性
将数据读入表中。然后添加属性以包含自定义元数据。
首先,将湿度和空气质量的测量值读入表中。显示前三行。
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
显示表的属性。属性对象 T.Properties
存储元数据,例如表的两个维的名称和表变量的名称。所有表都有这类具有相同属性的对象。(时间表也有类似的对象,其中包含额外的特定于时间的属性。)
T.Properties
ans = TableProperties with properties: Description: '' UserData: [] DimensionNames: {'Row' 'Variables'} VariableNames: {'Time' 'Humidity' 'AirQuality'} VariableDescriptions: {} VariableUnits: {} VariableContinuity: [] RowNames: {} CustomProperties: No custom properties are set. Use addprop and rmprop to modify CustomProperties.
此外,您可以指定自己的属性来存储自定义元数据。例如,使用 addprop
函数向表 T
添加属性,以获取仪器名称、测量精度和源文件的名称。对于一个元数据值对应一个变量的属性,请将属性类型指定为 'variable'
。对于一个值应用于整个表的属性,请指定 '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'} VariableDescriptions: {} VariableUnits: {} VariableContinuity: [] RowNames: {} Custom Properties (access using t.Properties.CustomProperties.<name>): SourceFile: [] Instrument: [] Precision: []
使用 addprop
创建自定义属性时,属性为空。要在自定义属性中存储元数据值,请使用圆点语法分配它们。
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'} 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]
向自定义属性分配由文本值组成的数组时,最佳做法是使用字符串数组,而不是字符向量元胞数组。如果使用字符向量元胞数组,将无法防止您以后将非文本值指定为元胞数组的元素。
输入参数
T
— 输入表
表 | 时间表
输入表,指定为表或时间表。
propertyNames
— 自定义属性的名称
字符向量 | 字符向量元胞数组 | 字符串数组
自定义属性的名称,指定为字符向量、字符向量元胞数组或字符串数组。
propertyTypes
— 属性类型
字符向量 | 字符向量元胞数组 | 字符串数组
属性类型,指定为字符向量、字符向量元胞数组或字符串数组。对于 propertyNames
指定的每个属性名称,请将对应的属性类型指定为 'table'
或 'variable'
。属性类型的数量必须等于属性名称的数量。
下表描述两种属性类型。
属性类型 | 描述 |
---|---|
| 该属性包含单个任意大小的值。该值作为元数据应用于整个表或时间表。 |
| 该属性包含一个数组,其中的每个值对应表或时间表中的一个变量。值是变量的元数据。数组中值的数量必须与变量的数量匹配。 属性存储的值与变量同步。当您采取以下动作时,它们会作出相应的响应:
|
版本历史记录
在 R2018b 中推出
MATLAB 命令
您点击的链接对应于以下 MATLAB 命令:
请在 MATLAB 命令行窗口中直接输入以执行命令。Web 浏览器不支持 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)