Egor Levchenko
Egor Levchenko

Reputation: 59

Split char vector of 0 and 1 to double

I have a char vector which looks like this:

char_vec = '001100';

And I want to make it just a double vector:

double_vec = [0, 0, 1, 1, 0, 0];

I gave an example with only 6 values, but actually I have a very long char vector (approx. 2000 values). So the splitting should work on any vector length.

Can you help me please with this problem?

Upvotes: 0

Views: 32

Answers (1)

L. Scott Johnson
L. Scott Johnson

Reputation: 4402

Use double and subtract the ascii value of character '0'

char_vec = '001100';

double_vec = double(char_vec-'0')

double_vec =

     0     0     1     1     0     0

Upvotes: 1

Related Questions