othman noor
othman noor

Reputation: 27

Merge two columns of bits to one column

In Matlab, how can I merge two bits from two columns (each column consist of one bit) into one column, for example:

X = [1,0;0,1;1,1;0,0;1,1;0,0]

The desired result is:

X = [10;01;11;00;11;00]

Upvotes: 2

Views: 72

Answers (2)

Robert Seifert
Robert Seifert

Reputation: 25232

An easy solution would be:

b = char(X+48)

If the char array is inconvenient, you can transform it to a cell array:

bcell = cellstr(b)

Upvotes: 2

Dennis Jaheruddin
Dennis Jaheruddin

Reputation: 21563

I may be thinking too easy here, but what about this:

10*X(:,1)+X(:,2)

Note that it will not actually show things like 01 as this is simplified to 1.

If you really want to show 01, you may need to process it as text:

Y=num2str(X)
Y(:,[1 end])

Upvotes: 1

Related Questions