addprop
向表或时间表添加自定义属性
说明
将包含自定义元数据的属性添加到表或时间表。输入参量 T2 = addprop(T1,propertyNames,propertyTypes)propertyNames 指定属性的名称。对于每个自定义属性,propertyTypes 指定属性中包含的元数据值是应用于整个输出表或时间表,还是应用于其变量。
使用 addprop 添加属性后,可以使用点号语法将元数据值赋给属性。
示例
将数据读入表中。然后添加属性以包含自定义元数据。
首先,将湿度和空气质量的测量值读入表中。
T = readtable("indoors.csv")T=60×3 table
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
2015-11-15 03:39:59 37 82
2015-11-15 04:53:11 36 80
2015-11-15 06:06:23 36 80
2015-11-15 07:19:35 36 80
2015-11-15 08:32:47 37 80
2015-11-15 09:45:59 37 79
2015-11-15 10:59:11 36 80
2015-11-15 12:12:23 37 80
2015-11-15 13:25:35 37 79
2015-11-15 14:38:46 36 83
2015-11-15 15:51:58 37 80
2015-11-15 17:05:10 36 80
2015-11-15 18:18:22 37 80
⋮
显示表的属性。属性对象 T.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.
此外,您可以指定自己的属性来存储自定义元数据。例如,使用 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'}
VariableTypes: ["datetime" "double" "double"]
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'}
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]
向自定义属性分配由文本值组成的数组时,最佳做法是使用字符串数组,而不是字符向量元胞数组。如果使用字符向量元胞数组,将无法防止您以后将非文本值指定为元胞数组的元素。
输入参数
输入表,指定为表或时间表。
自定义属性的名称,指定为字符串数组、字符向量或字符向量元胞数组。
属性类型,指定为字符串数组、字符向量或字符向量元胞数组。对于 propertyNames 指定的每个属性名称,请将对应的属性类型指定为 "table" 或 "variable"。属性类型的数量必须等于属性名称的数量。
下表描述两种属性类型。
属性类型 | 描述 |
|---|---|
| 该属性包含单个任意大小的值。该值作为元数据应用于整个表或时间表。 |
| 该属性包含一个数组,其中的每个值对应表或时间表中的一个变量。值是变量的元数据。数组中值的数量必须与变量的数量匹配。 属性存储的值与变量同步。当您采取以下动作时,它们会作出相应的响应:
|
输出参量
具有所添加属性的输出表,以表或时间表形式返回。
版本历史记录
在 R2018b 中推出
MATLAB Command
You clicked a link that corresponds to this MATLAB command:
Run the command by entering it in the MATLAB Command Window. Web browsers do not support MATLAB commands.
选择网站
选择网站以获取翻译的可用内容,以及查看当地活动和优惠。根据您的位置,我们建议您选择:。
您也可以从以下列表中选择网站:
如何获得最佳网站性能
选择中国网站(中文或英文)以获得最佳网站性能。其他 MathWorks 国家/地区网站并未针对您所在位置的访问进行优化。
美洲
- América Latina (Español)
- Canada (English)
- United States (English)
欧洲
- 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)