このページの内容は最新ではありません。最新版の英語を参照するには、ここをクリックします。
組み込みアプリケーションの単精度データ型の指定
単精度プロセッサをターゲットとするなど、コードで単精度のみを使用する場合、モデル コンフィギュレーション パラメーターとブロック パラメーターを使用してモデルに double が入り込まないようにできます。
単精度モデルの設計および検証については、浮動小数点組み込みモデルの検証を参照してください。Fixed-Point Designer™ がある場合、単精度コンバーター アプリを使用できます (単精度コンバーター (Fixed-Point Designer)を参照)。
指定不足の型の既定としての single データ型の使用
この例では、単精度ハードウェア ターゲット用に生成されたコードにおいて、倍精度データ型が採用されるのを避ける方法を示します。
信号の継承されたデータ型を指定するが、データ型伝播ルールが信号のデータ型を決定できない場合、信号データ型の既定は double です。モデル コンフィギュレーション パラメーターを使用して既定のデータ型を single として指定できます。
モデル例の確認
モデル例 UnderspecifiedDataType を開き、生成されたブロック名が表示されるように設定します。
model = 'UnderspecifiedDataType'; load_system(model) set_param(model,'HideAutomaticNames','off') open_system(model);

ルート入力端子 In2、In3、および In4 は [データ型] ブロック パラメーターに Inherit: Auto を指定します。下流ブロックも継承されたデータ型を使用します。
既定のデータ型として double をもつコードの生成
モデルはコンフィギュレーション パラメーター [システム ターゲット ファイル] を ert.tlc に設定して開始されます。これには Embedded Coder® が必要です。代わりに、[システム ターゲット ファイル] を grt.tlc に設定します。
set_param(model,'SystemTargetFile','grt.tlc')
モデルからコードを生成します。
slbuild(model)
### Searching for referenced models in model 'UnderspecifiedDataType'. ### Total of 1 models to build. ### Starting build procedure for: UnderspecifiedDataType ### Successful completion of build procedure for: UnderspecifiedDataType Build Summary Top model targets: Model Build Reason Status Build Duration ========================================================================================================================= UnderspecifiedDataType Information cache folder or artifacts were missing. Code generated and compiled. 0h 0m 6.663s 1 of 1 models built (0 models already up to date) Build duration: 0h 0m 7.1894s
コード生成レポートで、ファイル UnderspecifiedDataType.h を表示します。コードは、モデル内で入力データ型が指定不足のため、変数 In2、In3、および In4 の定義に double データ型を使用します。
cfile = fullfile('UnderspecifiedDataType_grt_rtw',... 'UnderspecifiedDataType.h'); coder.example.extractLines(cfile,... '/* External inputs (root inport signals with default storage) */',... '/* External outputs (root outports fed by signals with default storage) */',... 1, 0);
/* External inputs (root inport signals with default storage) */
typedef struct {
int8_T In1; /* '<Root>/In1' */
real_T In2; /* '<Root>/In2' */
real_T In3; /* '<Root>/In3' */
real_T In4; /* '<Root>/In4' */
} ExtU_UnderspecifiedDataType_T;
既定のデータ型として single をもつコードの生成
[コンフィギュレーション パラメーター] ダイアログ ボックスを開きます。[数学とデータ型] ペインの、[指定不足のデータ型の既定値] ドロップダウン リストで [single] を選択します。
あるいは、コマンド プロンプトで最適化を有効にします。
set_param(model, 'DefaultUnderspecifiedDataType', 'single');
モデルからコードを生成します。
slbuild(model)
### Searching for referenced models in model 'UnderspecifiedDataType'. ### Total of 1 models to build. ### Starting build procedure for: UnderspecifiedDataType ### Successful completion of build procedure for: UnderspecifiedDataType Build Summary Top model targets: Model Build Reason Status Build Duration ===================================================================================================== UnderspecifiedDataType Generated code was out of date. Code generated and compiled. 0h 0m 5.075s 1 of 1 models built (0 models already up to date) Build duration: 0h 0m 5.4807s
コード生成レポートで、ファイル UnderspecifiedDataType.h を表示します。コードは変数 In2、In3、および In4 の定義に single データ型を使用しています。
coder.example.extractLines(cfile,... '/* External inputs (root inport signals with default storage) */',... '/* External outputs (root outports fed by signals with default storage) */',... 1, 0);
/* External inputs (root inport signals with default storage) */
typedef struct {
int8_T In1; /* '<Root>/In1' */
real32_T In2; /* '<Root>/In2' */
real32_T In3; /* '<Root>/In3' */
real32_T In4; /* '<Root>/In4' */
} ExtU_UnderspecifiedDataType_T;