How to interpret Binary '0' and '1' as Decimal 0 and 1?

1 次查看(过去 30 天)
Hi all,
I have the following program:
c=dec2bin(0:3,2)
sum(sum(c))
And I get the output:
c =
00
01
10
11
s =
388
Instead of having s=4.
So how can I let matlab read the zeros and ones in the c matrix as decimal values?
Thanks a lot.
Hadi.

采纳的回答

David Young
David Young 2015-3-6
One way:
cdec = c - '0';

更多回答(0 个)

类别

Help CenterFile Exchange 中查找有关 Just for fun 的更多信息

Community Treasure Hunt

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

Start Hunting!

Translated by