表的自定义元数据及其变量,指定为 CustomProperties 对象。
CustomProperties 对象是可以添加到表中的自定义元数据的容器。默认情况下,CustomProperties 的属性为零。添加到 CustomProperties 的每个属性都可以包含表元数据或变量元数据。如果属性包含变量元数据,则其值必须是数组,并且数组中的元素数必须等于表变量的数量。
要将自定义元数据的属性添加到表中,请使用 addprop 函数。
要访问或修改自定义元数据,请使用语法 tableName.Properties.CustomProperties.PropertyName。在此语法中,PropertyName 是使用 addprop 添加该属性时选择的名称。
要删除属性,请使用 rmprop 函数。
注意:您只能使用 addprop 和 rmprop 为自定义元数据添加或删除属性。您不能添加或删除 tableName.Properties 对象的属性。
示例
创建一个表。
load patients
T = table(Gender,Age,Height,Weight,Smoker,Systolic,Diastolic);
添加可以保存有关表及其变量的自定义元数据的属性。在此示例中,元数据是仪器的名称,true 和 false 值指示是否绘制变量,以及输出文件的名称。要添加属性,请使用 addprop 函数。
T = addprop(T,{'Instrument','ToPlot','OutputFile'},{'variable','variable','table'});
T.Properties
ans =
TableProperties with properties:
Description: ''
UserData: []
DimensionNames: {'Row' 'Variables'}
VariableNames: {1x7 cell}
VariableDescriptions: {}
VariableUnits: {}
VariableContinuity: []
RowNames: {}
Custom Properties (access using t.Properties.CustomProperties.):
OutputFile: []
Instrument: []
ToPlot: []
使用圆点语法将值赋给自定义元数据。将由文本值构成的数组赋给自定义元数据时,最佳做法是使用字符串数组,而不是字符向量元胞数组。如果 CustomProperties 的属性是字符向量元胞数组,则无法防止您以后将非文本值指定为元胞数组的元素。
T.Properties.CustomProperties.Instrument = ["","","height rod","scale","","blood pressure cuff","blood pressure cuff"];
T.Properties.CustomProperties.ToPlot = [false false true true false true true];
T.Properties.CustomProperties.OutputFile = 'patientData.csv';
T.Properties
ans =
TableProperties with properties:
Description: ''
UserData: []
DimensionNames: {'Row' 'Variables'}
VariableNames: {1x7 cell}
VariableDescriptions: {}
VariableUnits: {}
VariableContinuity: []
RowNames: {}
Custom Properties (access using t.Properties.CustomProperties.):
OutputFile: 'patientData.csv'
Instrument: [1x7 string]
ToPlot: [0 0 1 1 0 1 1]
从 T 中删除 OutputFile 属性。
T = rmprop(T,'OutputFile');
T.Properties
ans =
TableProperties with properties:
Description: ''
UserData: []
DimensionNames: {'Row' 'Variables'}
VariableNames: {1x7 cell}
VariableDescriptions: {}
VariableUnits: {}
VariableContinuity: []
RowNames: {}
Custom Properties (access using t.Properties.CustomProperties.):
Instrument: [1x7 string]
ToPlot: [0 0 1 1 0 1 1]