How to access a group of bits from a string ?

2 Ansichten (letzte 30 Tage)
Abirami
Abirami am 27 Jan. 2015
Kommentiert: Abirami am 28 Jan. 2015
Hello,
I have a problem on how to access a specific range of bits from a given string
Consider I have a 20 bit string,I want to access the bit 1-6 and 7-12 and then 13-20. How do I do it in matlab? please help thanks in advance
Eg: X = 0 0 0 0 0 0 1 1 1 0 0 1 1 1 1 1 0 0 0 0
I want the output as
x1= 0 0 0 0 0 0
x2= 1 1 1 0 0 1
x3= 1 1 1 1 0 0 0 0
I have no idea how to do it.Please help. thanks in advance

Akzeptierte Antwort

Image Analyst
Image Analyst am 27 Jan. 2015
It's a little ambiguous, but how about just indexing or subtracting '0':
X = '0 0 0 0 0 0 1 1 1 0 0 1 1 1 1 1 0 0 0 0'
% Get rid of any spaces
X(X==' ') = []
% Extract the three substrings
x1 = X(1:6)
x2 = X(7:12)
x3 = X(13:end)
% Convert to a numerical data type.
doubleX = X - '0'
In the command window:
X =
0 0 0 0 0 0 1 1 1 0 0 1 1 1 1 1 0 0 0 0
X =
00000011100111110000
x1 =
000000
x2 =
111001
x3 =
11110000
doubleX =
0 0 0 0 0 0 1 1 1 0 0 1 1 1 1 1 0 0 0 0
I don't see why cell arrays would be necessary unless I misunderstood something.
  1 Kommentar
Abirami
Abirami am 28 Jan. 2015
I tried your method too sir and i found it easier..Thank u so much...

Melden Sie sich an, um zu kommentieren.

Weitere Antworten (0)

Kategorien

Mehr zu Characters and Strings finden Sie in Help Center und File Exchange

Tags

Community Treasure Hunt

Find the treasures in MATLAB Central and discover how the community can help you!

Start Hunting!

Translated by