MATLAB: How to print result of dec2bin to file

fprintf dec2bin

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!

Best Answer

fprintf(fid, [repmat('%c',1,size(B,2)) '\r\n'], B.');