Reputation: 599
I would like to convert a <1 x 8 cell> of chars
'111001' '00' '111000' '01' '1111' '10' '11101' '110'
to a <1 x 8 cell> of <1 x (length bitcode)> doubles
[111001] [00] [111000] [01] [1111] [10] [11101] [110]
How can I do this?
Upvotes: 7
Views: 5910
Reputation: 684
Try this:
s = {'111001','00','111000','01','1111','10','11101','110'}
num = str2num(str2mat(s));
Upvotes: 4
Reputation: 189
s = {'111001', '00', '111000', '01', '1111', '10', '11101', '110'};
d = cellfun(@(c_) c_ - '0', s, 'UniformOutput', false);
'01234' - '0'
will give 1 by 5 double matrix [0, 1, 2, 3, 4]
because '01234'
is actually char(['0', '1', '2', '3', '4'])
, and minus operation between characters will give the operation between their ASCII codes.
Upvotes: 6
Reputation: 3251
Try using str2num
to convert char arrays (strings) to numbers.
If you want to interpret the numbers as binary (base 2) numbers, try using bin2dec
.
Upvotes: 3