只需使用 2D 卷积(参见conv2 https://www.mathworks.com/help/matlab/ref/conv2.html).
2×2 情况,沿每个维度步骤 1
M = conv2(eye(N-1), miniM);
m
×m
案例,沿每个维度的步骤 1
M = conv2(eye(N-size(miniM-1)+1), miniM);
m
×n
情况下,沿每个维度的任意步骤
在这种情况下,需要定义步骤:
step = [2 1]; % desired step along each dimension
定义所需的重复次数更有意义R
,而不是最终尺寸(N
),因为后者可能无法通过完全重复来实现miniM
:
R = 4; % desired number of repetitions
Then:
M = conv2(full(sparse(1:step(1):step(1)*R, 1:step(2):step(2)*R, 1)), miniM);
Example:
>> miniM = [10 20 30; 40 50 60];
>> R = 4;
>> step = [1 2];
>> M = conv2(full(sparse(1:step(1):step(1)*R, 1:step(2):step(2)*R, 1)), miniM)
M =
10 20 30 0 0 0 0 0 0
40 50 70 20 30 0 0 0 0
0 0 40 50 70 20 30 0 0
0 0 0 0 40 50 70 20 30
0 0 0 0 0 0 40 50 60