How to combine two binary columns

조회 수: 9 (최근 30일)
Ennio Malvati
Ennio Malvati 2022년 10월 12일
편집: Fangjun Jiang 2022년 10월 12일
I have a table like this: [0 1 0 0 1, 1 0 1 1 0]
and i want to combine binary the two columns in order to obtain a column like this:
[01, 10, 01, 01, 10]. Ho can I do this?

채택된 답변

Fangjun Jiang
Fangjun Jiang 2022년 10월 12일
편집: Fangjun Jiang 2022년 10월 12일
a=[0 1 0 0 1;1 0 1 1 0]
a = 2×5
0 1 0 0 1 1 0 1 1 0
s=sprintf('%d%d\n',a(:))
s =
'01 10 01 01 10 '
Or
b=dec2bin(a)
b = 10×1 char array
'0' '1' '1' '0' '0' '1' '0' '1' '1' '0'
c=reshape(b,2,[])
c = 2×5 char array
'01001' '10110'
d=c'
d = 5×2 char array
'01' '10' '01' '01' '10'

추가 답변 (0개)

카테고리

Help CenterFile Exchange에서 Data Types에 대해 자세히 알아보기

Community Treasure Hunt

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

Start Hunting!

Translated by