Wrting binary data to text file

Hey everybody, I have some binary information, like a=[11110000 00001111 00000000 11111111], I want to write them to a text file. i tried with fprintf and fwrite but i couldn't! anybody has such a experience? Thanks a lot in advance. best.

3 件のコメント

Walter Roberson
Walter Roberson 2014 年 1 月 9 日
That first entry of "a": is it stored as decimal eleven million, one hundred and ten thousand? And size(a) is 1 x 4 ? Or is it stored as [1 1 1 1 0 0 0 0; 0 0 0 0 1 1 1 1; etc] and size(a) is 4 x 8? Or is it stored as {'11110000' '0000111' etc} ?
mahdi safarzadeh
mahdi safarzadeh 2014 年 1 月 9 日
I would say that is it stored as a 1*4 array of 8 bits binary data I mean instead of [0 4 8 16] I would to show my data like [00000000 00000100 00001000 00010000]
mahdi safarzadeh
mahdi safarzadeh 2014 年 1 月 9 日
I tried all the above forms, but i didn't work! I want to save my binary inputs. and these inputs are 8 bits data. actually they're complex, I mean the first 4 bits, real part and the last 4 bits img part. and after saving these inputs in a text file, I am going to separate the rael and imaginary part for furthure calculation. so i need these information to be saved as binary, as array of 8 bits.

サインインしてコメントする。

回答 (2 件)

Huang Andong
Huang Andong 2014 年 1 月 9 日

0 投票

a=[11110000; 00001111; 00000000; 11111111]; dlmwrite('C:\Users\dell\Desktop\a.txt',a);

1 件のコメント

mahdi safarzadeh
mahdi safarzadeh 2014 年 1 月 9 日
I tried this, But it didn't work! I want to save my binary inputs. and these inputs are e.g 8 bits data

サインインしてコメントする。

Walter Roberson
Walter Roberson 2014 年 1 月 9 日

0 投票

t = cellstr(dec2bin(a, 8));
fid = fopen('a.txt', 'wt');
fprintf(fid, '%s\n', t{:});
fclose(fid);

3 件のコメント

mahdi safarzadeh
mahdi safarzadeh 2014 年 1 月 14 日
Thanks a lot walter, I did like this and it worked:
In = ['11111111' , '00000000' , '10101010'];
filnam = '../user/inputs.stim';
fid = fopen(filnam,'w');
for i=1:size(In,1)
fprintf(fid,'%s\n', In(i,:));
end;
fclose(fid);
Walter Roberson
Walter Roberson 2014 年 1 月 14 日
That is not going to work.
>> ['11111111' , '00000000' , '10101010']
ans =
111111110000000010101010
Remember, [] is concatenation for strings. {} is for string arrays.
mahdi safarzadeh
mahdi safarzadeh 2014 年 1 月 14 日
yo are right, it should be like: [ '11111111' ; '00000000' ...

サインインしてコメントする。

カテゴリ

ヘルプ センター および File ExchangeData Type Conversion についてさらに検索

質問済み:

2014 年 1 月 9 日

コメント済み:

2014 年 1 月 14 日

Community Treasure Hunt

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

Start Hunting!

Translated by