Printing cell array values as simple numbers?

1 次查看(过去 30 天)
Hello,
I would like to display the cells of cell array in the following form: 01000001000000010000000000... etc.
How do I print a cell array into such form? Using disp(binaryArray) command only shows the cell arrays contents as in the attached picture. Any help is appreciated!

采纳的回答

Adam Danz
Adam Danz 2021-1-14
编辑:Adam Danz 2021-1-14
Options to convert a 1xn cell array containing scalar numbers to a vector (or string)
rng('default') % for reproducibility
x = num2cell(randi(2,1,10)-1) % demo cell with 1 element per cell
x = 1x10 cell array
{[1]} {[1]} {[0]} {[1]} {[1]} {[0]} {[0]} {[1]} {[1]} {[1]}
% 1)
cell2mat(x)
ans = 1×10
1 1 0 1 1 0 0 1 1 1
% 2)
[x{:}]
ans = 1×10
1 1 0 1 1 0 0 1 1 1
% 3)
sprintf('%d',[x{:}]) % note: character array
ans = '1101100111'

更多回答(0 个)

类别

Help CenterFile Exchange 中查找有关 Cell Arrays 的更多信息

产品


版本

R2020b

Community Treasure Hunt

Find the treasures in MATLAB Central and discover how the community can help you!

Start Hunting!

Translated by