matlab之repmat

来源:互联网 发布:淘宝客如意投怎么设置 编辑:程序博客网 时间:2024/06/10 08:07
repmat
Replicate and tile arrayexpand all in pageSyntax
B = repmat(A,n) 
exampleB = repmat(A,sz1,sz2,...,szN) 
exampleB = repmat(A,sz) 
exampleDescription
exampleB = repmat(A,n) returns an n-by-n tiling of A. The size of B is size(A) * n
exampleB = repmat(A,sz1,sz2,...,szN) specifies a list of scalars, sz1,sz2,...,szN, to describe an N-D tiling of A. The size of B is [size(A,1)*sz1, size(A,2)*sz2,...,size(A,n)*szN]. For example, repmat([1 2; 3 4],2,3) returns a 4-by-6 matrix.

exampleB = repmat(A,sz) specifies a row vector, sz, instead of a list of scalars, to describe the tiling of A. This syntax returns the same output as the previous syntax. For example, repmat([1 2; 3 4],[2 3]) returns the same result as repmat([1 2; 3 4],2,3).


Examples
collapse allReplicate and Tile a MatrixCreate a diagonal matrix.
A = diag([100 200 300])A =


   100     0     0
     0   200     0
     0     0   300Create a 2-by-2 tiling of A.
B = repmat(A,2)B =


   100     0     0   100     0     0
     0   200     0     0   200     0
     0     0   300     0     0   300
   100     0     0   100     0     0
     0   200     0     0   200     0
     0     0   300     0     0   300Replicate and Tile an N-D ArrayCreate a 2-by-2-by-2 array.
A = zeros(2,2,2);
A(:,:,1) = diag([10 20]);
A(:,:,2) = diag([55 99]);
AA(:,:,1) =


    10     0
     0    20




A(:,:,2) =


    55     0
     0    99Create a 3-by-3 tiling of A.
B = repmat(A,3)B(:,:,1) =


    10     0    10     0    10     0
     0    20     0    20     0    20
    10     0    10     0    10     0
     0    20     0    20     0    20
    10     0    10     0    10     0
     0    20     0    20     0    20




B(:,:,2) =


    55     0    55     0    55     0
     0    99     0    99     0    99
    55     0    55     0    55     0
     0    99     0    99     0    99
    55     0    55     0    55     0
     0    99     0    99     0    99Vertical Stack of Row VectorsCreate a row vector.
A = 1:4A =


     1     2     3     4
Create a vertical stack of four copies of A.
B = repmat(A,4,1)B =


     1     2     3     4
     1     2     3     4
     1     2     3     4
     1     2     3     4
B contains 4 copies of A in the first dimension and 1 copy in the second dimension. This result is equivalent to B = repmat(A,[4 1]).
Horizontal Stack of Column VectorsCreate a column vector.
A = (1:3)'A =


     1
     2
     3Create a horizontal stack of four copies of A.
B = repmat(A,1,4)B =


     1     1     1     1
     2     2     2     2
     3     3     3     3B contains 1 copy of A in the first dimension and 4 copies in the second dimension. This result is equivalent to B = repmat(A,[1 4]).
Replicate and Tile a Complex Scalar ValueDefine a complex scalar value.
A = 5+1i;Create a 3-by-2 tiling of A.
B = repmat(A,[3 2])B =


   5.0000 + 1.0000i   5.0000 + 1.0000i
   5.0000 + 1.0000i   5.0000 + 1.0000i
   5.0000 + 1.0000i   5.0000 + 1.0000iB contains 3 copies of A in the first dimension and 2 copies in the second dimension. This result is equivalent to B = repmat(A,3,2).
Replicate and Tile a Cell ArrayCreate a cell array containing a string and numeric values.
A = {'Values'; 10; 105}A = 


    'Values'
    [ 10]
    [105]
Create a 3-by-2 tiling of A.
B = repmat(A,[3 2])B = 


    'Values'    'Values'
    [    10]    [    10]
    [   105]    [   105]
    'Values'    'Values'
    [    10]    [    10]
    [   105]    [   105]
    'Values'    'Values'
    [    10]    [    10]
    [   105]    [   105]
B contains 3 copies of A in the first dimension and 2 copies in the second dimension. This result is equivalent to B = repmat(A,3,2).

0 0
原创粉丝点击