How to access a group of bits from a string ?

3 ビュー (過去 30 日間)
Abirami
Abirami 2015 年 1 月 27 日
コメント済み: Abirami 2015 年 1 月 28 日
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

採用された回答

Image Analyst
Image Analyst 2015 年 1 月 27 日
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 件のコメント
Abirami
Abirami 2015 年 1 月 28 日
I tried your method too sir and i found it easier..Thank u so much...

サインインしてコメントする。

その他の回答 (0 件)

カテゴリ

Help Center および File ExchangeLogical についてさらに検索

タグ

Community Treasure Hunt

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

Start Hunting!

Translated by