Effacer les filtres
Effacer les filtres

storing binary data as .txt file and as binary data

10 vues (au cours des 30 derniers jours)
hardik
hardik le 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?

Réponses (2)

Thomas
Thomas le 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 le 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.

Catégories

En savoir plus sur Data Type Conversion dans Help Center et File Exchange

Community Treasure Hunt

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

Start Hunting!

Translated by