フィルターのクリア

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 Center および File ExchangeWaveform Generation についてさらに検索

製品

Community Treasure Hunt

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

Start Hunting!

Translated by