2014-06-28 143 views

回答

4

我不知道的方法使用repmat但这里是用kron

kron([1 2 ; 3 4],[1 1;1 1]) 

ans = 

1  1  2  2 
1  1  2  2 
3  3  4  4 
3  3  4  4 
+0

这简单的克朗工作!非常感谢你! – user3354883

0

的,它使用repmat

A=[1 2; 3 4]; 
cell2mat(arrayfun(@(x)repmat(x,2,2),A,'UniformOutput',false)) 

ans = 

1  1  2  2 
1  1  2  2 
3  3  4  4 
3  3  4  4 

arrayfun用于在A每个元素评估替代方法使用匿名函数@(x)repmat(x,2,2)将该单个元素复制到2x2矩阵中。

arrayfun的结果是一个2x2单元阵列,其中每个元素是一个2x2矩阵。然后我们通过cell2mat将这个单元阵列转换成矩阵。

0

让数据被定义为

A = [1 2; 3 4]; 
R = 2; %// number of repetitions of each row 
C = 2; %// number of repetitions of each column. May be different from R 

两种可能的方法如下:

  1. 最简单的方法是使用索引:真的

    B = A(ceil(1/R:1/R:size(A,1)), ceil(1/C:1/C:size(A,2))); 
    
  2. 如果您想用repmat来做,你需要使用permutereshape:将原始尺寸1,2移动到尺寸2,4(permute);沿着新的维度重复1,3(repmat);塌陷尺寸1,2为一名维和3,4为另一尺寸(reshape):

    [r c] = size(A); 
    B = reshape(repmat(permute(A, [3 1 4 2]), [R 1 C 1]), [r*R c*C]); 
    

实施例导致对其R=2C=3(与任何两种方法获得的):

B = 
    1  1  1  2  2  2 
    1  1  1  2  2  2 
    3  3  3  4  4  4 
    3  3  3  4  4  4