如何在Matlab上展开矩阵? [英] How to unfold a Matrix on Matlab?
本文介绍了如何在Matlab上展开矩阵?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!
问题描述
我有一个给定的矩阵 H
,我想通过以下方法展开(展开)以找到矩阵 B
:
I have a given matrix H
and I would like to unfold (expand) it to find a matrix B
by following the method below :
让 H
为尺寸为 m×n
的矩阵.让 x = gcd(m,n)
Let H
be a matrix of dimension m × n
. Let x = gcd (m,n)
- 矩阵
H
分为两部分. - 切割模式如下:
- 对角切割"指的是是通过将
c = n/x
个单位向右交替移动(我们将c
个单位向右移动几次)来实现的. - 我们交替向下移动
cb = m/x
个单位(即b =(nm)/x
)(向下移动b
个单位几次). - The "diagonal cut" is made by alternately moving
c = n/x
units to the right (we movec
units to the right several times). - We alternately move
c-b = m/x
units down (i.e.b = (n-m)/x
) (we moveb
units down several times). - After applying this "diagonal cut" of the matrix, we copy and paste the two parts repeatedly to obtain the matrix B.
- 在应用此对角切口"之后,矩阵,我们重复复制和粘贴两个部分以获得矩阵B.
示例:让尺寸为 m×n = 5×10
的矩阵 H
由:
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
分为两部分.切割方式如下: - Diagonal cutting diagram : The matrix
H
is cut in two parts. The cutting pattern is such that : - 我们将
c = 2
个单位向右移动几次c = 2
个单位向右 - 我们反复向下移动
c-b = 1
个单位. - We move
c = 2
units to the right several timesc = 2
units to the right, - We repeatedly move
c - b = 1
unit downwards. - After applying this "diagonal cut" of the matrix, we copy and paste the two parts repeatedly to obtain the matrix :
- 结果矩阵
B
为(L
为因数): - The resulting matrix
B
is (L
is factor) :
我们得到:
- 在应用此对角切口"之后,对于矩阵,我们重复复制并粘贴两个部分以获得矩阵:
备注:在矩阵 X
, X1
和 X2
中,破折号为零.
Remark : In the matrices X
, X1
and X2
the dashes are zeros.
有什么建议吗?
推荐答案
这可以通过创建带有切割图案的逻辑蒙版,然后逐个将输入乘以蒙版及其取反来实现.可以使用 blkdiag
重复 L
.
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{:});
这篇关于如何在Matlab上展开矩阵?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!
查看全文