Main Content

AddProp

Add custom properties to table or timetable

Description

例子

t = addprop(t,,,,属性名称,,,,PropertyTypes在表或时间表中添加包含自定义元数据的属性t。the input argument属性名称指定属性的名称。对于每个自定义属性,PropertyTypes指定属性中包含的元数据值是否适用于t从总体上或变量t

在使用属性添加属性之后AddProp,您可以使用点语法为属性分配元数据值。

例子

全部收缩

将数据读取到表中。然后添加属性以包含自定义元数据。

首先,将湿度和空气质量的测量读取到桌子上。显示前三行。

T = readtable ('indoors.csv');头(T,3)
ans =3×3桌时间湿度空气___________________ ___________________ 2015-11-15 00:24 36 80 2015-11-15 01:13:35 36 80 2015-11-15 02:26:47 37 37 79 79

Display the properties of the table. The properties object,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对于仪器名称,测量精度和源文件的名称。对于每个变量具有一个元数据值的属性,请指定'多变的'作为属性类型。对于具有适用于整个表的一个值的属性,请指定'table'

t = addprop(t,{'Instrument',,,,'精确',,,,'源文件'},{'多变的',,,,'多变的',,,,'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.): SourceFile: [] Instrument: [] Precision: []

当您使用自定义属性使用AddProp,,,,the properties are empty. To store metadata values in the custom properties, assign them using dot syntax.

t.properties.customproperties.insportiment = ["clock"“湿度计”"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:{}自定义属性(使用t.properties.customproperties访问。):sourcefile:'indoors.csv'乐器:[“时钟”“ hygrometer”“ hygrometer”“ air质量仪表”,“空气质量仪”。[NAN 0.5000 0.1000]

当您为自定义属性分配文本值数组时,最好的做法是使用字符串数组,而不是字符向量的单元格数组。如果您使用字符向量的单元格数组,则没有任何机制可以防止您以后将非下文值分配为单元阵列的元素。

输入参数

全部收缩

输入表,指定为表或时间表。

自定义属性的名称,指定为字符向量,字符向量的单元格数组或字符串数​​组。

Property types, specified as a character vector, cell array of character vectors, or string array. For each property name specified by属性名称,,,,specify the corresponding property type as either'table'or'多变的'。属性类型的数量必须等于属性名称的数量。

该表描述了两种属性类型。

Property Type

Description

'table'

该属性包含一个任意大小的单个值。该值以元数据或整个时间表的形式应用于元数据或时间表。

'多变的'

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.

属性存储的值与变量同步。当您采取以下操作之一时,它们会做出回应:

  • Move variables — The corresponding values in the property are reordered.

  • Add variables — Default values are added as corresponding values in the property.

  • 删除变量 - 相应的值将从属性中删除。

版本历史记录

在R2018B中引入