want to print a matrix with in bits form
Mostrar comentarios más antiguos
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 comentarios
James Tursa
el 22 de Feb. de 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?
Respuestas (2)
James Tursa
el 22 de Feb. de 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
Walter Roberson
el 27 de Feb. de 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);
Categorías
Más información sobre Creating and Concatenating Matrices en Centro de ayuda y File Exchange.
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!