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?
C = cellstr( A ) converts A to a cell array of character vectors. For instance, if A is a string, "foo" , C is a cell array containing a character vector, {'foo'} . C = cellstr( A , dateFmt ) , where A is a datetime or duration array, applies the specified format, such as "HH:mm:ss" .
To create a cell array of character vectors, use curly braces, {} , just as you would to create any cell array. For example, use a cell array of character vectors to store a list of names.
C = num2cell( A ) converts array A into cell array C by placing each element of A into a separate cell in C . The num2cell function converts an array that has any data type—even a nonnumeric type.
here's a one liner solution:
a=num2cell(str2double(s))
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.
Try this:
s = {'111001','00','111000','01','1111','10','11101','110'}
num = str2num(str2mat(s));
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
.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With