How to access a group of bits from a string ?

5 Ansichten (letzte 30 Tage)
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
0 Kommentare-2 ältere Kommentare anzeigen-2 ältere Kommentare ausblenden

Melden Sie sich an, um zu kommentieren.

Akzeptierte Antwort

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-1 ältere Kommentare anzeigen-1 ältere Kommentare ausblenden
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.

Kategorien

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

Community Treasure Hunt

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

Start Hunting!

Translated by