decimal array from logical array

Hi,
I need to convert a logical array into a decimal array, but the logical elements need to be grouped in pairs. An example would make this clearer:
I have a logical array such as:
>> a = logical([1,0,1,1,1,0; 1,1,0,0,0,1; 0,1,1,1,0,1])
a =
1 0 1 1 1 0
1 1 0 0 0 1
0 1 1 1 0 1
and I want to convert that to decimal with each 2 bits being 1 number:
b =
2 3 2
3 0 1
1 3 1
Does anyone know a clever/ fast MATLAB way of doing this, rather than the boring/slow for-loop way?

 채택된 답변

David Young
David Young 2012년 1월 16일

1 개 추천

2*a(:, 1:2:end) + a(:, 2:2:end)

추가 답변 (1개)

Chris
Chris 2012년 1월 17일

0 개 추천

Of course! Life is so simple if you open your eyes! Thank you :)

카테고리

도움말 센터File Exchange에서 Creating and Concatenating Matrices에 대해 자세히 알아보기

질문:

2012년 1월 16일

Community Treasure Hunt

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

Start Hunting!

Translated by