table 入力の定義
table 入力をコマンド ラインで定義できます。前提条件 (assert ステートメント) を使用した table 入力の型のプログラムによる指定はサポートされません。
コマンド ラインでの table 入力の定義
コマンド ラインで table 入力を定義するには、入力の例を提供するか table 型を使用します。定数の table 入力を指定することもできます。
table 入力の例の提供
-args オプションを使用します。
T = table(A,B,C,'VariableNames',vnames); fiaccel myFunction -args {T}
table の型の指定
fiaccel への table の型を指定するには、次のようにします。
table を定義します。以下に例を示します。
T = table(A,B,C,'VariableNames',vnames);Tから型を作成します。t = coder.typeof(T);
-argsオプションを使用して、型をfiaccelに渡します。fiaccel myFunction -args {t}
定数 table 入力の指定
table 入力が定数であることを指定するには、-args オプションと coder.Constant を併用します。
T = table(A,B,C,'VariableNames',vnames); fiaccel myFunction -args {coder.Constant(T)}
table の表現
table の coder 型オブジェクトは、オブジェクトとそのプロパティを記述します。coder.typeof または coder.newtype を使用して新しい table 型を作成します。
coder 型オブジェクトは、内部状態の値を除外して、オブジェクトのプロパティの簡潔な説明を表示します。コマンド ライン インターフェイスで表示されるのは、非定数プロパティの型とサイズ、定数プロパティの値です。たとえば、3 行 3 列のサイズの coder table 型を作成します。
A = [1 2 3]'; B = [4 5 6]'; C = [7 8 9]'; t = table(A,B,C); tType = coder.typeof(t)
変数 t の表現が coder 型オブジェクト tType に格納されます。
tType =
matlab.coder.type.TableType
3x3 table
Data : 1x3 homogeneous cell
Description : 1x0 char
UserData : 0x0 double
DimensionNames : {'Row'} {'Variables'}
VariableNames : {'A'} {'B'} {'C'}
VariableDescriptions : 1x3 homogeneous cell
VariableUnits : 1x3 homogeneous cell
VariableContinuity : 1x3 matlab.internal.coder.tabular.Continuity
RowNames : 0x0 homogeneous celltable coder 型の従来の coder.ClassType 表現が必要な場合は、メソッド getCoderType を使用して取得できます。たとえば、tType オブジェクトの基になる coder.ClassType 表現を確認するには、次のコマンドを使用します。
tType.getCoderType
ans =
coder.ClassType
1×1 table
Properties :
data : 1×0 homogeneous cell
cell with no elements
metaDim : 1×1 matlab.internal.coder.tabular.private.metaDim
Properties :
labels : {'Row'} {'Variables'}
length : 1×1 double
rowDim : 1×1 matlab.internal.coder.tabular.private.rowNamesDim
Properties :
labels : 0×0 homogeneous cell
cell with no elements
length : 0
varDim : 1×1 matlab.internal.coder.tabular.private.varNamesDim
Properties :
descrs : 1×0 homogeneous cell
cell with no elements
units : 1×0 homogeneous cell
cell with no elements
continuity : 0×0 double
customProps : 1×1 struct with no fields
hasDescrs : 1×1 logical
hasUnits : 1×1 logical
hasContinuity : 1×1 logical
hasCustomProps : 1×1 logical
labels :
length : 1×1 double
arrayProps : 1×1 struct
Description: 1×0 char
UserData: 0×0 doubleオブジェクトのプロパティ
coder table 型オブジェクトのプロパティを編集できます。オブジェクトのプロパティにスカラー値を割り当てることができます。coder 型オブジェクトのプロパティに値を割り当てると、対応する coder 型の値に暗黙的に変換されます。オブジェクト自体のサイズを変更するには、coder.resize 関数を使用するか、オブジェクトのプロパティを直接編集します。
coder.resize を使用したオブジェクトのプロパティのサイズ変更
coder.resize を使用して、table オブジェクトのサイズとオブジェクトのプロパティのサイズを変更できます。プロパティ内で配列を作成することもできます。
たとえば、3 行 3 列のサイズの coder table 型を作成します。Description プロパティのサイズは 1 行 0 列です。
A = [1 2 3]'; B = [4 5 6]'; C = [7 8 9]'; t = table(A,B,C); tType = coder.typeof(t)
tType =
matlab.coder.type.TableType
3x3 table
Data : 1x3 homogeneous cell
Description : 1x0 char
UserData : 0x0 double
DimensionNames : {'Row'} {'Variables'}
VariableNames : {'A'} {'B'} {'C'}
VariableDescriptions : 1x3 homogeneous cell
VariableUnits : 1x3 homogeneous cell
VariableContinuity : 1x3 matlab.internal.coder.tabular.Continuity
RowNames : 0x0 homogeneous cellcoder.resize を使用して、Description を上限が 12 の可変長にします。
tType.Description = coder.resize(tType.Description,[1 12],[0 1])
tType =
matlab.coder.type.TableType
3x3 table
Data : 1x3 homogeneous cell
Description : 1x:12 char
UserData : 0x0 double
DimensionNames : {'Row'} {'Variables'}
VariableNames : {'A'} {'B'} {'C'}
VariableDescriptions : 1x3 homogeneous cell
VariableUnits : 1x3 homogeneous cell
VariableContinuity : 1x3 matlab.internal.coder.tabular.Continuity
RowNames : 0x0 homogeneous cellオブジェクトのサイズを直接変更
特定のタイプのオブジェクトについては、オブジェクトのプロパティを編集することでオブジェクト自体のサイズを変更することもできます。たとえば、tType オブジェクトの行数を変更するには、Size プロパティを編集します。
tType.Size = [10 3]
tType =
matlab.coder.type.TableType
10x3 table
Data : 1x3 homogeneous cell
Description : 1x:12 char
UserData : 0x0 double
DimensionNames : {'Row'} {'Variables'}
VariableNames : {'A'} {'B'} {'C'}
VariableDescriptions : 1x3 homogeneous cell
VariableUnits : 1x3 homogeneous cell
VariableContinuity : 1x3 matlab.internal.coder.tabular.Continuity
RowNames : 0x0 homogeneous cellVarDims プロパティを使用して行数を可変サイズにすることもできます。
tType.VarDims = [true false]
tType =
matlab.coder.type.TableType
:10x3 table
Data : 1x3 homogeneous cell
Description : 1x:12 char
UserData : 0x0 double
DimensionNames : {'Row'} {'Variables'}
VariableNames : {'A'} {'B'} {'C'}
VariableDescriptions : 1x3 homogeneous cell
VariableUnits : 1x3 homogeneous cell
VariableContinuity : 1x3 matlab.internal.coder.tabular.Continuity
RowNames : 0x0 homogeneous cell
参考
table | coder.Constant | coder.newtype | coder.typeof