Saving data as binary
27 ビュー (過去 30 日間)
古いコメントを表示
Basically, i have for example k = [0 5 4], i want it to be saved as [0 101 100] instead of [00000000 00000101 00000100] so that it takes the least size possible, how can i do that ?
0 件のコメント
回答 (2 件)
Voss
2022 年 5 月 14 日
k = [0 5 4];
arrayfun(@(x)dec2bin(x,max(1,ceil(log2(x)))),k,'UniformOutput',false)
11 件のコメント
Walter Roberson
2022 年 5 月 20 日
bits = {[1] [0 0] [1] [0 1 1] }
Bitstream = [bits{:}];
fid = fopen('test.bin','w');
fwrite(fid, Bitstream, 'bit1');
fclose(fid);
Ilya Dikariev
2022 年 5 月 20 日
k_new=str2num(dec2bin(k))' would do. But if you want to still reduce the the size, just use dec2bin which keeps the data in char type which is 8 times smaller
1 件のコメント
Walter Roberson
2022 年 5 月 20 日
編集済み: Walter Roberson
2022 年 5 月 20 日
only 4 times smaller. Each character needs 16 bits.
If you uint8(k_new) then that would need only one byte per value
参考
カテゴリ
Help Center および File Exchange で Large Files and Big Data についてさらに検索
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!