フィルターのクリア

How to output multiple types of binary files in one file

1 回表示 (過去 30 日間)
수환 김
수환 김 2022 年 3 月 24 日
編集済み: Chunru 2022 年 3 月 25 日
I'm trying to output the DF to a binary file with one line. I'll show you a simple example.(In reality, it consists of hundreds of millions of rows of data.).
  1. A1 should be uint32_t, B2 should be float32, and C3 should be uint32_t.
  2. 'Little endian encoding' is required.
DF=
A1 B2 C3
1 7 13
2 8 14
3 9 15
4 10 16
5 11 17
6 12 18
The expected result after output is as follows.
Binary file =
1(uint32) 7(float32) 13(uint32) 2(uint32) 8(float32) 14(uint32) 3(uint32) 9(float32) 15(uint32) 4(uint32) 10(float32) 16(uint32) 5(uint32) 11(float32) 17(uint32) 6(uint32) 12(float32) 18(uint32)

回答 (1 件)

Chunru
Chunru 2022 年 3 月 24 日
編集済み: Chunru 2022 年 3 月 25 日
x = [
1 7 13
2 8 14
3 9 15
4 10 16
5 11 17
6 12 18];
fid = fopen("test.bin", "w", "ieee-le");
for i=1:size(x, 1)
% 1(uint32) 7(float32) 13(uint32)
fwrite(fid, x(i, 1), "uint32");
fwrite(fid, x(i, 2), "float32");
fwrite(fid, x(i, 3), "uint32");
end
fclose(fid);
dir
. .. test.bin

カテゴリ

Help Center および File ExchangeFile Operations についてさらに検索

製品

Community Treasure Hunt

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

Start Hunting!

Translated by