is there a function in matlab that creates a binary repetition coder ?

for example when i enter a sequence 0010110 ;when n=3
the result will be 000000111000111111000

 採用された回答

Azzi Abdelmalek
Azzi Abdelmalek 2012 年 12 月 25 日
編集済み: Azzi Abdelmalek 2012 年 12 月 25 日

0 投票

s='0010110'
out=repmat(s,3,1)
out=out(:)'
%or
s=[0 0 1 0 1 1 0];
out=reshape(repmat(s,3,1),1,[])

7 件のコメント

mary
mary 2012 年 12 月 25 日
thank you indeed .. but can you tell me what 1 refers to in (s,3,1) and then what is the other one and the []??
Azzi Abdelmalek
Azzi Abdelmalek 2012 年 12 月 25 日
out=repmat(s,3,1) % will repeat s 3 times verticaly and once hrizontaly reshape(M,1,[]) reshape a matrix M to one line, [ ] means that matlab will determine the lentgh
mary
mary 2012 年 12 月 25 日
okey Mr.Azzi thank you so much .
mary
mary 2012 年 12 月 25 日
but when i want to decode what function should i use?
Azzi Abdelmalek
Azzi Abdelmalek 2012 年 12 月 25 日
a=reshape(out,3,[]);
b=a(1,:)
José-Luis
José-Luis 2012 年 12 月 25 日
b=a(1:3:numel(a));
mary
mary 2012 年 12 月 25 日
okey it worked .. thanx alot :)

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

その他の回答 (1 件)

Nasser M. Abbasi
Nasser M. Abbasi 2012 年 12 月 25 日

0 投票

You did not say what is the class of 0010110, so I assume cell array.
r = {'0' '0' '1' '0' '1' '1' '0'};
n = 3;
reshape(repmat(r,n,1),1,n*numel(r))'
ans =
'0'
'0'
'0'
'0'
'0'
'0'
'1'
'1'
'1'
'0'
'0'
'0'
'1'
'1'
'1'
'1'
'1'
'1'
'0'
'0'
'0'
This is a cell. Now you can do with it any conversion you want.
--Nasser

2 件のコメント

mary
mary 2012 年 12 月 25 日
it is a 1 by n matrix .. by the way can you help me with generating such an array of zeros and ones?? thanx alot
mary
mary 2012 年 12 月 25 日
i mean such a matrix of 1 by n dimensions?

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

カテゴリ

ヘルプ センター および File ExchangeMATLAB についてさらに検索

Community Treasure Hunt

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

Start Hunting!

Translated by