How to print result of dec2bin to file
28 次查看(过去 30 天)
显示 更早的评论
Example:
A = (0:255);
B = dec2bin(A);
fid = fopen('test.txt' , 'w');
fprintf(fid, '%s', B);
fclose(fid);
When you execute the above the fprintf function prints out the first column of the entire B array and then the entire second column, and so on. That is, it doesn't print the entire first binary value and then the entire second binary value and so on.
How do I fix this?
Thanks!
0 个评论
采纳的回答
更多回答(2 个)
Jan
2011-8-26
The output is written columnwise, but DEC2BIN replies the string in row-orientation. Therefore transposing should solve the problem:
fprintf(fid, '%s', transpose(B));
0 个评论
Jonathon
2011-9-5
1 个评论
Walter Roberson
2011-9-6
Use
fprintf(fid, '%s\n', transpose(B));
if you want different lines. Your original code that Jan was going on would have put everything on the same line.
另请参阅
类别
在 Help Center 和 File Exchange 中查找有关 Characters and Strings 的更多信息
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!