如何通过重复矩阵​​行来放大矩阵?

时间:2018-03-21 06:06:15

标签: matlab matrix reshape

初始矩阵为A = [ [1 2 3; 4 5 6; 7 8 9]。每行要复制3次,以便输出矩阵

B = [1 2 3;1 2 3;1 2 3;4 5 6; 4 5 6; 4 5 6; 7 8 9; 7 8 9; 7 8 9]
B = replicate(permute(A,[3 2 1]),3,1)

3 个答案:

答案 0 :(得分:2)

你的意思是那样的吗?

kron(A,ones(3,1))

ans =

 1     2     3
 1     2     3
 1     2     3
 4     5     6
 4     5     6
 4     5     6
 7     8     9
 7     8     9
 7     8     9

答案 1 :(得分:2)

R2015a 以来,有一个专用函数:repelem

A = [1 2 3; 4 5 6; 7 8 9]
B = repelem(A,3,1)
B =

     1     2     3
     1     2     3
     1     2     3
     4     5     6
     4     5     6
     4     5     6
     7     8     9
     7     8     9
     7     8     9

答案 2 :(得分:1)

或者只是编制索引:

A = [1 2 3; 4 5 6; 7 8 9]; % original matrix
m = 3; % row repetition factor
n = 1; % column repetition factor
B = A(ceil(1/m:1/m:size(A,1)), ceil(1/n:1/n:size(A,2)));