Array of 1 and 0 to decimal

조회 수: 4 (최근 30일)
Hg
Hg 2016년 4월 19일
편집: John D'Errico 2016년 4월 19일
How to convert array with 1's and 0's (array A) to decimal (array B)?
A = [1 0 0 1 0 0 1 1; 0 0 0 0 1 1 1 1; 1 0 1 0 1 0 1 0 ];
B = [147;15;170];

채택된 답변

John D'Errico
John D'Errico 2016년 4월 19일
편집: John D'Errico 2016년 4월 19일
B = bin2dec(char(A + '0'))
B =
147
15
170

추가 답변 (1개)

Azzi Abdelmalek
Azzi Abdelmalek 2016년 4월 19일
A = [1 0 0 1 0 0 1 1; 0 0 0 0 1 1 1 1; 1 0 1 0 1 0 1 0 ];
out=A*2.^(size(A,2)-1:-1:0)'

카테고리

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

태그

제품

Community Treasure Hunt

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

Start Hunting!

Translated by