want to print a matrix with in bits form
2 ビュー (過去 30 日間)
古いコメントを表示
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 件のコメント
James Tursa
2017 年 2 月 22 日
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?
回答 (2 件)
James Tursa
2017 年 2 月 22 日
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 件のコメント
Walter Roberson
2017 年 2 月 27 日
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 件のコメント
参考
カテゴリ
Help Center および File Exchange で Logical についてさらに検索
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!