addprop
カスタム プロパティを table または timetable に追加
説明
T = addprop( はカスタム メタデータを含むプロパティを table または timetable T,propertyNames,propertyTypes)T に追加します。入力引数 propertyNames はプロパティの名前を指定します。各カスタム プロパティについて、propertyTypes はプロパティに含まれるメタデータ値が T 全体に適用されるか、T の変数に適用されるかを指定します。
addprop を使用してプロパティを追加した後に、ドット構文を使用してメタデータ値をプロパティに代入できます。
例
データを table に読み取ります。その後、カスタム メタデータを含むプロパティを追加します。
まず、湿度と大気質の測定値を table に読み取ります。最初の 3 行を表示します。
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
table のプロパティを表示します。プロパティ オブジェクト T.Properties は、table の 2 次元の名前や table 変数の名前などのメタデータを格納します。すべての table には、同じプロパティをもつこのようなオブジェクトがあります (timetable にも、時間に固有のプロパティを追加で含む類似のオブジェクトがある)。
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 を使用して、計器名、測定精度およびソース ファイル名のプロパティを table T に追加します。変数ごとに 1 つのメタデータ値をもつプロパティには、プロパティ タイプとして 'variable' を指定します。table 全体に適用される値を 1 つもつプロパティには、'table' を指定します。
T = addprop(T,{'Instrument','Precision','SourceFile'},{'variable','variable','table'});
T.Propertiesans =
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]
テキスト値の配列をカスタム プロパティに代入する場合は、文字ベクトルの cell 配列ではなく、string 配列を使用することをお勧めします。文字ベクトルの cell 配列を使用する場合、後で cell 配列の要素として非テキスト値が割り当てられることを防ぐメカニズムはありません。
入力引数
入力 table。table または timetable として指定します。
カスタム プロパティの名前。文字ベクトル、文字ベクトルの cell 配列、または string 配列として指定します。
プロパティ タイプ。文字ベクトル、文字ベクトルの cell 配列、または string 配列として指定します。propertyNames で指定された各プロパティ名について、対応するプロパティ タイプを 'table' または 'variable' のいずれかとして指定します。プロパティ タイプの数はプロパティ名の数と等しくなければなりません。
次の表では、2 つのプロパティ タイプを説明します。
プロパティ タイプ | 説明 |
|---|---|
| このプロパティは任意のサイズの単一の値を含みます。値はメタデータとして table または timetable 全体に適用されます。 |
| このプロパティは、table または timetable の変数ごとに 1 つの値をもつ配列を含みます。値は変数のメタデータです。配列内の値の数は変数の数と一致しなければなりません。 プロパティが格納する値は、その変数と同期されます。次の操作のいずれかを実行すると反応します。
|
バージョン履歴
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.
Web サイトの選択
Web サイトを選択すると、翻訳されたコンテンツにアクセスし、地域のイベントやサービスを確認できます。現在の位置情報に基づき、次のサイトの選択を推奨します:
また、以下のリストから Web サイトを選択することもできます。
最適なサイトパフォーマンスの取得方法
中国のサイト (中国語または英語) を選択することで、最適なサイトパフォーマンスが得られます。その他の国の 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)