フィルターのクリア

storing binary data as .txt file and as binary data

10 ビュー (過去 30 日間)
hardik
hardik 2012 年 5 月 8 日
i have a bunch of numbers x=[1:1:100]; to convert them to binary i used y=dec2bin(x,8); how do i store this "y" converted data as a .txt file? i need the information stored as binary data. what there options are there?
and is there a format where i can store the x numbers as a binary numbers?

回答 (2 件)

Thomas
Thomas 2012 年 5 月 8 日
You could also try
% this will show the pretty output formatted file..
x=[1:1:100];
y=dec2bin(x,8);
new=cellstr(y);
fileID = fopen('exp.txt','w');
fprintf(fileID,'%s\n',new{:});
fclose(fileID)

Walter Roberson
Walter Roberson 2012 年 5 月 8 日
fid = fopen('YourOutputFile.txt', 'wt');
fwrite(fid, y);
fclose(fid);
There is no fprintf() format that takes decimal numbers as input and writes out strings of '0' and '1'. Strings of '0' and '1' as produced by dec2bin() is not called "binary" in traditional computer programming. "binary" in traditional computer programming always refers to a numeric format, not to a string format.

カテゴリ

Help Center および File ExchangeData Type Conversion についてさらに検索

Community Treasure Hunt

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

Start Hunting!

Translated by