txtファイルから符号付固定小数点の16進数を読み込み、fiオブジェクトを作る方法を教えてください。
2 views (last 30 days)
Show older comments
下記のコードで作成される d.txt を読み込み、
元の符号付固定小数点の16進数のfiオブジェクト a_fiと同じ設定のfiオブジェクトを作成するにはどうしたらよいでしょうか。
(d.txtは、実際は外部で取得することを想定しています)
a = randn(1,10);
T = numerictype(true,64,60);
F = fimath('OverflowMode', 'saturate',...
'RoundMode', 'round',...
'SumMode', 'FullPrecision',...
'ProductMode', 'FullPrecision',...
'MaxProductWordLength', 256,...
'MaxSumWordLength', 256);
a_fi = fi(a,T,F);
b_fi = hex(a_fi);
c = strsplit(b_fi)';
writecell(c,"d.txt", QuoteStrings="none");
0 Comments
Accepted Answer
Atsushi Ueno
on 22 Jul 2022
a = randn(1,10);
T = numerictype(true,12,10);
F = fimath('OverflowMode', 'saturate',...
'RoundMode', 'round',...
'SumMode', 'FullPrecision',...
'ProductMode', 'FullPrecision',...
'MaxProductWordLength', 256,...
'MaxSumWordLength', 256);
a_fi = fi(a,T,F);
b_fi = hex(a_fi) % a_fi の値 (16進数で表示)
c = strsplit(b_fi)';
writecell(c,"d.txt", QuoteStrings="none");
d = regexprep(fileread('d.txt'),'\n',' ') % 下記のコードで作成される d.txt を読み込み
d_fi = fi(0,T,F); % 元の符号付固定小数点の16進数のfiオブジェクト a_fi と同じ設定の fi オブジェクトを作成
d_fi.hex = d; % d.txt の内容を16進数として d_fi に設定
a_fi == d_fi % d_fi が a_fi と同じ値か確認
More Answers (0)
See Also
Categories
Find more on FPGA, ASIC, and SoC Development in Help Center and File Exchange
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!