want to print a matrix with in bits form
2 views (last 30 days)
Show older comments
S0=[01 00 11 10;11 10 01 00;00 10 01 11;11 01 11 10] this matrix is appeared like this
S0 = 1 0 11 10
11 10 1 0
0 10 1 11
11 1 11 10
but i want to print this matrix like this
S0 =
01 00 11 10
11 10 01 00
00 10 01 11
11 01 11 10
2 Comments
James Tursa
on 22 Feb 2017
Do you mean you want MATLAB to automatically put leading 0's in front of double values in a matrix when it displays the matrix? Or are you just asking for a way to print it like that manually with some code or function?
Answers (2)
James Tursa
on 22 Feb 2017
If you are just trying to manually print the matrix in that format, e.g.,
for k=1:size(S0,1)
fprintf(' %02d',S0(k,:));
fprintf('\n')
end
0 Comments
Walter Roberson
on 27 Feb 2017
S0=[01 00 11 10;11 10 01 00;00 10 01 11;11 01 11 10];
S1 = arrayfun( @(v) [floor(v/10), mod(v,10)], S0, 'Uniform', 0);
This will create a 4 x 4 array of cells, and each cell will be a 1 x 2 double which is the binary.
Binary adds a dimension to your existing 4 x 4 array and it is not clear how you would like that dimension represented.
Perhaps you would like
S1 = arrayfun( @(v) char('0' + [floor(v/10), mod(v,10)]), S0, 'Uniform', 0);
but if so then the simpler method would be
S1 = arrayfun(@(v) sprintf('%02d', v), S0, 'Uniform', 0);
0 Comments
See Also
Categories
Find more on Logical 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!