txtファイルから符​号付固定小数点の16​進数を読み込み、fi​オブジェクトを作る方​法を教えてください。

6 views (last 30 days)
K_S_
K_S_ on 22 Jul 2022
Commented: K_S_ on 25 Jul 2022
下記のコードで作成される 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");

Accepted Answer

Atsushi Ueno
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進数で表示)
b_fi = 'e61 ca1 a3b 7ff 047 800 193 472 d97 f97'
c = strsplit(b_fi)';
writecell(c,"d.txt", QuoteStrings="none");
d = regexprep(fileread('d.txt'),'\n',' ') % 下記のコードで作成される d.txt を読み込み
d = 'e61 ca1 a3b 7ff 047 800 193 472 d97 f97 '
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 と同じ値か確認
ans = 1×10 logical array
1 1 1 1 1 1 1 1 1 1
  1 Comment
K_S_
K_S_ on 25 Jul 2022
ありがとうございました。無事できました。

Sign in to comment.

More Answers (0)

Tags

Products


Release

R2022a

Community Treasure Hunt

Find the treasures in MATLAB Central and discover how the community can help you!

Start Hunting!