필터 지우기
필터 지우기

how to adding zero of specific position into binary sequence?

조회 수: 1 (최근 30일)
z m
z m 2017년 10월 14일
답변: Image Analyst 2017년 10월 14일
i have binary sequence
A= [ 1 1 1 1 1 0 0 1 0 1 1 1 1 1 1 0 0 1] >>> 18 bits.
and wants to add zero (specific position)to binary sequence after every 4th bit of A so the output will be
B=[1 1 1 1 0 1 0 0 1 0 0 1 1 1 0 1 1 1 0 0 0 1]>>> 22 bit.
how to do this using matlab ? is there any syntax for it? also, i want to get back the first binary sequence of A from B which removes the zeros from B to get A again?
pls, help me to do it.
thanks.

답변 (1개)

Image Analyst
Image Analyst 2017년 10월 14일
Sounds like homework, so I'm only giving a partial solution. But all you have to do is to figure out how to crop B to the right length:
A= [ 1 1 1 1 1 0 0 1 0 1 1 1 1 1 1 0 0 1]
% Make sure A is a multiple of 4
lenA = length(A)
newLength = ceil(lenA/4) * 4
% Pad to end with 0
A(newLength) = 0;
% Make into matrix.
a2 = reshape(A, 4, [])
% Tack on row of zeros
[rows, columns] = size(a2);
a2(rows+1, columns) = 0
% Reshape back to 1-d
B = a2(:)'
% Now crop off some B if needed. Hint: use rem().

카테고리

Help CenterFile Exchange에서 Waveform Generation에 대해 자세히 알아보기

제품

Community Treasure Hunt

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

Start Hunting!

Translated by