Array of 1 and 0 to decimal

7 次查看(过去 30 天)
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 Types 的更多信息

标签

产品

Community Treasure Hunt

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

Start Hunting!

Translated by