このページの翻訳は最新ではありません。ここをクリックして、英語の最新版を参照してください。
coder.ClassType クラス
パッケージ: coder
スーパークラス: coder.ArrayType
MATLAB クラスのセットを表します。
説明
生成コードが受け入れることができる値クラス オブジェクトのセットを指定します。codegen
-args
オプションでのみ使用します。生成された MEX 関数に入力として渡さないでください。
構築
メモ
coder.Type
オブジェクトの作成と編集は、コード生成の型エディターを使用して対話形式で行うこともできます。コード生成の型エディターを使用した入力の型の作成と編集を参照してください。
はオブジェクト t
= coder.typeof(value_class_object
)value_class_object
の coder.ClassType
オブジェクトを作成します。
はクラス t
= coder.newtype(value_class_name
)value_class_name
のオブジェクトに coder.ClassType
オブジェクトを作成します。
入力引数
|
v = myValueClass; t = coder.typeof(v); t = coder.typeof(myValueClass(2,3)); |
|
MATLAB® パス上にある値クラス定義ファイルの名前。文字ベクトルまたは string スカラーとして指定します。次に例を示します。 t = coder.newtype('myValueClass'); |
プロパティ
関数 coder.typeof
を使用して値クラス オブジェクト v
から coder.ClassType
オブジェクト t
を作成するときに、t
のプロパティは、属性 Constant
が false
に設定された v
のプロパティと同じになります。
コピーのセマンティクス
値。値クラスがコピー操作に与える影響については、オブジェクトのコピーを参照してください。
例
オブジェクト例に基づく型の作成
ワークスペース内のオブジェクト例に基づいて型を作成します。
値クラス myRectangle
を作成します。
classdef myRectangle properties length; width; end methods function obj = myRectangle(l,w) if nargin > 0 obj.length = l; obj.width = w; end end function area = calcarea(obj) area = obj.length * obj.width; end end end
myRectangle
のオブジェクトを入力として取得する関数を作成します。
function z = getarea(r) %#codegen z = calcarea(r); end
myRectangle
のオブジェクトを作成します。
v = myRectangle(1,2)
v = myRectangle with properties: length: 1 width: 2
v
に基づく coder.ClassType
オブジェクトを作成します。
t = coder.typeof(v)
t = coder.ClassType 1×1 myRectangle length: 1×1 double width : 1×1 double
coder.typeof
は、v
と同じプロパティ名とタイプをもつ coder.ClassType
オブジェクトを作成します。
getarea
のコードを生成します。coder.ClassType
オブジェクト t
を -args
オプションに渡すことで、入力の型を指定します。
codegen getarea -args {t} -report
coder.newtype
を使用した型の作成
coder.newtype
を使用して、値クラス mySquare
のオブジェクトに coder.ClassType
オブジェクトを作成します。
1 つのプロパティ side
をもつ値クラス mySquare
を作成します。
classdef mySquare properties side; end methods function obj = mySquare(val) if nargin > 0 obj.side = val; end end function a = calcarea(obj) a = obj.side * obj.side; end end end
mySquare
の coder.ClassType
型を作成します。
t = coder.newtype('mySquare')
前の手順によって t
の coder.ClassType
型が作成されますが、これには mySquare
のプロパティは割り当てられません。t
に mySquare
のすべてのプロパティが確実に割り当てられるようにするには、t.Properties
を使用して side
の型を指定します。
t.Properties.side = coder.typeof(2)
ヒント
coder.ClassType
の作成後、プロパティのタイプを変更できます。次に例を示します。t = coder.typeof(myClass) t.Properties.prop1 = coder.typeof(int16(2)); t.Properties.prop2 = coder.typeof([1 2 3]);
coder.ClassType
の作成後、プロパティを追加できます。次に例を示します。t = coder.typeof(myClass) t.Properties.newprop1 = coder.typeof(int8(2)); t.Properties.newprop2 = coder.typeof([1 2 3]);
コードを生成するとき、
codegen
に渡されるcoder.ClassType
オブジェクトのプロパティはクラス定義ファイル内のプロパティと一致していなければなりません。ただし、コードで使用されていないプロパティがクラス定義ファイルに存在する場合、coder.ClassType
オブジェクトはこれらのプロパティを含める必要はありません。コード ジェネレーターは、使用されていないプロパティを削除します。
バージョン履歴
R2017a で導入