Shift left and replace the LSB bit?
14 ビュー (過去 30 日間)
古いコメントを表示
I want to replace the LSB bit with logical 1 or 0. I have 10/8 array. It is replacing the LSB bit only for the first row. But for the second row onwards it is not working.
01111111
11111110
00000010
00001010
00100110
10000010
11111110
00000010
00001011
00101100
Every row should be shifted left and replaced with logic 0 or 1 which is stored in some variable let it be 'kj'. The code I written was
ex=bu(i,:) % here bu is char array
z = [ex(2:end), '0']
kj=num2str(out); %out is logical 1 or 0
z(i,8)=kj;
c=z(i,:)
getting c for the first row correctly but from second row onwards it is giving a single bit like 0 or 1.
0 件のコメント
採用された回答
James Tursa
2018 年 3 月 15 日
編集済み: James Tursa
2018 年 3 月 15 日
bu = your char array
result = bu(:,2:end);
result(:,end+1) = new_bit_char;
E.g.,
>> bu = char((rand(5,8)<0.5)+'0') % some random sample data
bu =
10110111
01000111
11101100
01100101
00111111
>> new_bit_char = '1'
new_bit_char =
1
>> result = bu(:,2:end)
result =
0110111
1000111
1101100
1100101
0111111
>> result(:,end+1) = new_bit_char
result =
01101111
10001111
11011001
11001011
01111111
その他の回答 (0 件)
参考
カテゴリ
Help Center および File Exchange で Logical についてさらに検索
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!