How to print result of dec2bin to file
이전 댓글 표시
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!
채택된 답변
추가 답변 (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));
Jonathon
2011년 9월 5일
0 개 추천
댓글 수: 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.
카테고리
도움말 센터 및 File Exchange에서 Creating and Concatenating Matrices에 대해 자세히 알아보기
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!