setfimath
fimath
オブジェクトを fi
オブジェクトに付加
説明
は、Y
= setfimath(X
,F
)X
の numerictype
と値をもち、fimath
オブジェクト F
が付加されている fi
オブジェクト Y
を返します。
構文 Y = setfimath(X,F)
は入力 X
を変更しません。X
を変更するには、X = setfimath(X,F)
を使用します。これを使用すると、生成コードにデータ コピーを作成せずに fimath
の設定をローカルで詳細に制御できます。
式で setfimath
を使用する場合 (a*setfimath(b,F)
など)、fimath
オブジェクトは一時変数で使用されますが b
は変更されません。
この関数および関連する関数 removefimath
は、両方のオペランドの fimath
が等しくなければならないというエラーを回避するのにも役立ちます。
例
fimath
オブジェクトを fi
オブジェクトに付加
fi
オブジェクトを作成します。
a = fi(pi)
a = 3.1416 DataTypeMode: Fixed-point: binary point scaling Signedness: Signed WordLength: 16 FractionLength: 13
fimath
オブジェクトを作成し、setfimath
を使用して fi
オブジェクトに付加します。
f = fimath('OverflowAction','Wrap','RoundingMethod','Floor'); b = setfimath(a,f)
b = 3.1416 DataTypeMode: Fixed-point: binary point scaling Signedness: Signed WordLength: 16 FractionLength: 13 RoundingMethod: Floor OverflowAction: Wrap ProductMode: FullPrecision SumMode: FullPrecision
コード生成での fimath
の設定と削除
この例では、パターン X = setfimath(X,F)
と Y = removefimath(Y)
を使用して、変数の fimath
設定が関数の外部から影響を受けないようにする方法を示します。このパターンは生成コードでデータのコピーを作成しません。
type fixed_point_32bit_KeepLSB_plus_example.m
function y = fixed_point_32bit_KeepLSB_plus_example(a,b) f = fimath('RoundingMethod', 'Floor', ... 'OverflowAction', 'Wrap', ... 'SumMode', 'KeepLSB', ... 'SumWordLength', 32) a = setfimath(a,f); b = setfimath(b,f); y = a + b; y = removefimath(y); end
a = fi(0,1,16,15); b = fi(0,1,16,15);
MATLAB® Coder™ を使用して C コードを生成できます。この例では、32 ビットのネイティブ整数型をもつコンピューターで C コードを生成します。
codegen -config:lib fixed_point_32bit_KeepLSB_plus_example... -args {a,b} -launchreport Code generation successful: View report
コード生成レポートでコードをトレースします。
入力引数
X
— 入力配列
スカラー | ベクトル | 行列 | 多次元配列
入力配列。スカラー、ベクトル、行列または多次元配列として指定します。
fimath
オブジェクトは、X
が fi
オブジェクトまたは整数のデータ型の場合に適用されます。それ以外の場合、fimath
オブジェクトは適用されず、Y = X
となります。
データ型: single
| double
| int8
| int16
| int32
| int64
| uint8
| uint16
| uint32
| uint64
| fi
複素数のサポート: あり
F
— 出力に付加する固定小数点演算の設定
fimath
オブジェクト
出力に付加する固定小数点演算の設定。既存の fimath
オブジェクトとして指定します。F
が fimath
オブジェクトでない場合、エラーが発生します。
出力引数
拡張機能
C/C++ コード生成
MATLAB® Coder™ を使用して C および C++ コードを生成します。
バージョン履歴
R2012b で導入
参考
fi
| fimath
| fixed.fimathLike
| removefimath
MATLAB コマンド
次の MATLAB コマンドに対応するリンクがクリックされました。
コマンドを MATLAB コマンド ウィンドウに入力して実行してください。Web ブラウザーは MATLAB コマンドをサポートしていません。
Select a Web Site
Choose a web site to get translated content where available and see local events and offers. Based on your location, we recommend that you select: .
You can also select a web site from the following list:
How to Get Best Site Performance
Select the China site (in Chinese or English) for best site performance. Other MathWorks country sites are not optimized for visits from your location.
Americas
- América Latina (Español)
- Canada (English)
- United States (English)
Europe
- 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)