I have a given matrix H
and I would like to unfold (expand) it to find a matrix B
by following the method below :
Let H
be a matrix of dimension m × n
. Let x = gcd (m,n)
H
is cut in two parts.c = n/x
units to the right (we move c
units to the right several times).c-b = m/x
units down (i.e. b = (n-m)/x
) (we move b
units down several times).Exemple : Let the matrix H
of dimension m × n = 5 × 10
defined by :
1 0 1 1 1 0 1 1 0 0
0 1 1 0 0 1 1 0 1 1
1 1 0 1 1 1 0 1 0 0
0 1 1 0 1 0 1 0 1 1
1 0 0 1 0 1 0 1 1 1
x = gcd (m,n) = gcd (5,10) = 5
,c = n/x = 10/5 = 2
,b = (n-m)/x = (10-5)/5 = 1
.H
is cut in two parts.
The cutting pattern is such that :c = 2
units to the right several times c = 2
units to the right,c - b = 1
unit downwards.Remark : In the matrices X
, X1
and X2
the dashes are zeros.
B
is (L
is factor) :Any suggestions?
This can be done by creating a logical mask with the cutting pattern, and then element-wise multiplying the input by the mask and by its negation. Repeating by L
can be done with blkdiag
.
H = [1 0 1 1 1 0 1 1 0 0
0 1 1 0 0 1 1 0 1 1
1 1 0 1 1 1 0 1 0 0
0 1 1 0 1 0 1 0 1 1
1 0 0 1 0 1 0 1 1 1];
L = 2;
[m, n] = size(H);
x = gcd(m, n);
c = n / x;
b = (n-m)/x;
mask = repelem(tril(true(m/b)), b, c);
A = [H.*mask; H.*~mask];
A = repmat({A}, L, 1);
B = blkdiag(A{:});