Shift left and replace the LSB bit?

조회 수: 14 (최근 30일)
RAKESH REDDY
RAKESH REDDY 2018년 3월 15일
댓글: RAKESH REDDY 2018년 3월 18일
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.

채택된 답변

James Tursa
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 CenterFile Exchange에서 Logical에 대해 자세히 알아보기

태그

Community Treasure Hunt

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

Start Hunting!

Translated by