Reputation: 27
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
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
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