How do i write something like this 10100 as bits to a file ?
Show older comments
Hello everyone. I have a cell array like this:
' ' 5 '00'
'E' 5 '010'
'T' 5 '011'
'R' 3 '100'
'A' 2 '1010'
'I' 2 '1011'
'N' 2 '1100'
'.' 1 '11010'
'B' 1 '11011'
'H' 1 '11100'
'L' 1 '11101'
'S' 1 '11110'
'V' 1 '11111'
This cell array i used to store the number of appearances of a character in a file.After that it stores the code obtained after Shannon Fano compression algorithm. Can you please tell me how do i write the code of each simbol to a file.As for example:
V{I,3} = 11011
so that each 1 and 0 is considered a bit.
I tried something as this :
fwrite(F,V{I,3},'bit1');
but i not sure if this is correct.
Answers (2)
Azzi Abdelmalek
on 17 Nov 2014
a={' ' 5 '00'
'E' 5 '010'
'T' 5 '011'
'R' 3 '100'
'A' 2 '1010'
'I' 2 '1011'
'N' 2 '1100'
'.' 1 '11010'
'B' 1 '11011'
'H' 1 '11100'
'L' 1 '11101'
'S' 1 '11110'
'V' 1 '11111'}
fid=fopen('file.txt','w')
for k=1:size(a,1)
fprintf(fid,'%s\t %d\t %s\r\n',a{k,:})
end
fclose(fid)
Shadia Sultana
on 28 Mar 2021
0 votes
a={' ' 5 '00'
'E' 5 '010'
'T' 5 '011'
'R' 3 '100'
'A' 2 '1010'
'I' 2 '1011'
'N' 2 '1100'
'.' 1 '11010'
'B' 1 '11011'
'H' 1 '11100'
'L' 1 '11101'
'S' 1 '11110'
'V' 1 '11111'}
fid=fopen('file.txt','w')
for k=1:size(a,1)
fprintf(fid,'%s\t %d\t %s\r\n',a{k,:})
end
fclose(fid)
Categories
Find more on Data Import and Analysis 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!