hex
fi
オブジェクトの格納整数の 16 進数表現
説明
例
fi
オブジェクトの格納整数の 16 進数形式の確認
値 -1
および 1
、語長 8 ビット、小数部の長さ 7 ビットの符号付き fi
オブジェクトを作成します。
a = fi([-1 1], 1, 8, 7)
a = -1.0000 0.9922 DataTypeMode: Fixed-point: binary point scaling Signedness: Signed WordLength: 8 FractionLength: 7
fi
オブジェクト a
の格納整数の 16 進数表現を確認します。
b = hex(a)
b = '80 7f'
ファイルへの 16 進数データの書き込み
この例では、MATLAB ワークスペースからテキスト ファイルに 16 進数データを書き込む方法を示します。
データを定義し、hexdata.txt
という名前の書き込み可能なテキスト ファイルを作成します。
x = (0:15)'/16; a = fi(x, 0, 16, 16); h = fopen('hexdata.txt', 'w');
関数 fprintf
を使用して hexdata.txt
ファイルにデータを書き込みます。
for k = 1:length(a) fprintf(h, '%s\n', hex(a(k))); end fclose(h);
作成したファイルの内容を表示するには、関数 type
を使用します。
type hexdata.txt
0000 1000 2000 3000 4000 5000 6000 7000 8000 9000 a000 b000 c000 d000 e000 f000
ファイルからの 16 進数データの読み取り
この例では、テキスト ファイルから MATLAB ワークスペースに 16 進数データを読み戻す方法を示します。
データを定義し、hexdata.txt
という名前の書き込み可能なテキスト ファイルを作成し、hexdata.txt
ファイルにデータを書き込みます。
x = (0:15)'/16; a = fi(x, 0, 16, 16); h = fopen('hexdata.txt', 'w'); for k = 1:length(a) fprintf(h, '%s\n', hex(a(k))); end fclose(h);
hexdata.txt
を読み取り用に開き、その内容をワークスペース変数に読み取ります。
h = fopen('hexdata.txt', 'r'); nextline = ''; str = ''; while ischar(nextline) nextline = fgetl(h); if ischar(nextline) str = [str; nextline]; end end fclose(h);
正しいスケーリングの fi
オブジェクトを作成し、変数 str
に格納された 16 進数値を代入します。
b = fi([], 0, 16, 16); b.hex = str
b = 0 0.0625 0.1250 0.1875 0.2500 0.3125 0.3750 0.4375 0.5000 0.5625 0.6250 0.6875 0.7500 0.8125 0.8750 0.9375 DataTypeMode: Fixed-point: binary point scaling Signedness: Unsigned WordLength: 16 FractionLength: 16
入力引数
a
— 入力配列
fi
オブジェクト
入力配列。fi
オブジェクトとして指定します。
データ型: fi
バージョン履歴
R2006a より前に導入
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)