Filter löschen
Filter löschen

storing binary data as .txt file and as binary data

10 Ansichten (letzte 30 Tage)
hardik
hardik am 8 Mai 2012
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?

Antworten (2)

Thomas
Thomas am 8 Mai 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 am 8 Mai 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.

Kategorien

Mehr zu Data Type Conversion finden Sie in Help Center und File Exchange

Community Treasure Hunt

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

Start Hunting!

Translated by