Clear Filters
Clear Filters

storing binary data as .txt file and as binary data

10 views (last 30 days)
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?

Answers (2)

Thomas
Thomas on 8 May 2012
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 on 8 May 2012
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.

Categories

Find more on Data Type Conversion 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!