Generator matrix for repetition coding

3 Ansichten (letzte 30 Tage)
freebil
freebil am 7 Jun. 2016
Kommentiert: Azzi Abdelmalek am 7 Jun. 2016
Hello. I would like to be able to make generator repetition matrices for given vectors. If I have the vector
u = [1 0 0 1]
with parameter q=3(how many times every bit will be repeated), I would like to take from matlab the G matrix
G = [1 1 1 0 0 0 0 0 0 0 0 0;
0 0 0 1 1 1 0 0 0 0 0 0;
0 0 0 0 0 0 1 1 1 0 0 0;
0 0 0 0 0 0 0 0 0 1 1 1];
So the multiplication
c = u*G
gives
c = [1 1 1 0 0 0 0 0 0 1 1 1];
So, I would like to give u,q inputs to matlab and get G for very big matrices. Basically, the creation of G matrix requires only the length of u and the q. If the length of u=3 and q=2, we have
G = [1 1 0 0 0 0;
0 0 1 1 0 0;
0 0 0 0 1 1];

Akzeptierte Antwort

Azzi Abdelmalek
Azzi Abdelmalek am 7 Jun. 2016
Bearbeitet: Azzi Abdelmalek am 7 Jun. 2016
Edited
u=3;
q=2;
C=zeros(u,q*u);
jj=1:q;
for k=1:u
C(k,jj)=1;
jj=jj+q;
end
C
%Or
u=4
q=3
C=zeros(u,q*u)
jj=1:q
x=reshape(repmat(1:u,q,1),[],1)'
y=1:q*u
idx=sub2ind(size(C),x,y)
C(idx)=1
%Or
u=4
q=3
d=mat2cell(ones(1,q*u),1,q*ones(1,u))
out=blkdiag(d{:})
  4 Kommentare
freebil
freebil am 7 Jun. 2016
Bearbeitet: freebil am 7 Jun. 2016
Thank you very much for your answer!
Azzi Abdelmalek
Azzi Abdelmalek am 7 Jun. 2016
u=10^5;
q=3;
C=sparse(u,q*u);
jj=1:q;
x=reshape(repmat(1:u,q,1),[],1)';
y=1:q*u;
idx=sub2ind(size(C),x,y);
C(idx)=1;

Melden Sie sich an, um zu kommentieren.

Weitere Antworten (0)

Community Treasure Hunt

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

Start Hunting!

Translated by