主要内容

repmat

Repeat copies of array

描述

example

b =repmat(A,n)返回一个包含的数组ncopies ofAin the row and column dimensions. The size ofBsize(A)*nwhenA是a matrix.

example

b =repmat(A,R1,...,RN)specifies a list of scalars,R1,..,RN, that describes how copies ofAare arranged in each dimension. WhenAhasN尺寸,大小Bsize(A).*[r1...rN]. For example,repmat([1 2; 3 4],2,3)returns a 4-by-6 matrix.

example

b =repmat(A,r)用行矢量指定重复方案r. For example,repmat(A,[2 3])returns the same result asrepmat(a,2,3).

例子

全部收缩

创建一个3×2矩阵se elements contain the value 10.

A = repmat(10,3,2)
A =3×210 10 10 10 10 10 10

将矩阵的副本重复为2 x-2块排列。

a = diag([100 200 300])
A =3×3100 0 0 0 0 200 0 0 0 300
b = repmat(a,2)
b =6×6100 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 300

Repeat copies of a matrix into a 2-by-3 block arrangement.

a = diag([100 200 300])
A =3×3100 0 0 0 0 200 0 0 0 300
b =repmat(a,2,3)
b =6×9100 0 0 0 100 0 0 100 0 0 0 0 200 0 0 200 0 0 0 0 0 0 0 0 0 300 0 0 300 0 0 300 0 0 300 0 0 0 100 0 0 0 100 0 0 0 0 0 0 200 0 0 200 0 0 200 0 0 200 0 0 0 0 0 0 300 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0300 0 0 300

将矩阵的重复副本重复为2 x-3-by-2块排列。

a = [1 2;3 4]
A =2×21 2 3 4
b = repmat(a,[2 3 2])
b = b(:,:,1)= 1 2 1 2 1 2 3 4 3 4 3 4 1 2 1 2 1 2 1 2 3 4 3 4 3 4 b(:,::, :, :,2)= 1 2 1 2 1 2 1 23 4 3 4 3 4 1 2 1 2 1 2 3 4 3 4 3 4

垂直堆叠行矢量四次。

a = 1:4;b = repmat(a,4,1)
b =4×41 2 3 4 1 2 3 4 1 2 3 4 1 2 3 4

Horizontally stack a column vector four times.

A = (1:3)'; B = repmat(A,1,4)
b =3×41 1 1 1 2 2 2 2 3 3 3 3

Create a table with variablesAge高度.

A = table([39; 26],[70; 63],'VariableNames',{'年龄''高度'})
A=2×2桌子Age Height ___ ______ 39 70 26 63

将表的副本重复为2 x-3块格式。

b =repmat(a,2,3)
B=4×6桌Age Height Age_1 Height_1 Age_2 Height_2 ___ ______ _____ ________ _____ ________ 39 70 39 70 39 70 26 63 26 63 26 63 39 70 39 70 39 70 26 63 26 63 26 63

repmatrepeats the entries of the table and appends a number to the new variable names.

Input Arguments

全部收缩

输入数组, specified as a scalar, vector, matrix, or multidimensional array.

Data Types:single|双倍的|int8|INT16|INT32|INT64|uint8|UINT16|uint32|uint64|logical|char|string|struct|桌子|约会时间|duration|日历|分类|细胞
Complex Number Support:Yes

在行和列尺寸中重复输入数组的次数,指定为整数值。如果n0or negative, the result is an empty array.

Data Types:single|双倍的|int8|INT16|INT32|INT64|uint8|UINT16|uint32|uint64

Repetition factors for each dimension, specified as separate arguments of integer values. If any repetition factor is0or negative, the result is an empty array.

Data Types:single|双倍的|int8|INT16|INT32|INT64|uint8|UINT16|uint32|uint64

每个维度的重复因子的向量,指定为整数值的行矢量。如果有任何值r0or negative, the result is an empty array.

Data Types:single|双倍的|int8|INT16|INT32|INT64|uint8|UINT16|uint32|uint64

提示

  • 要通过与一个数组形成输入的张量产品来构建块数组,请使用克朗. For example, to stack the row vectorA = 1:3垂直四次,您可以使用b =克朗(A,ones(4,1)).

  • To create block arrays and perform a binary operation in a single pass, usebsxfun. In some cases,bsxfun提供更简单,更有效的回忆解决方案。例如,添加向量A = 1:5b =(1:10)'要产生10 x 5阵列,请使用bsxfun(@plus,a,b)instead ofrepmat(A,10,1) + repmat(B,1,5).

  • 什么时候A是a scalar of a certain type, you can use other functions to get the same result asrepmat.

    repmatSyntax Equivalent Alternative
    repmat(Nan,M,N) NaN(m,n)
    repmat(single(inf),m,n) inf(m,n,'single')
    repmat(int8(0),m,n) zeros(m,n,'int8')
    repmat(uint32(1),m,n) ones(m,n,'uint32')
    repmat(EPS,M,N) eps(ones(m,n))

Extended Capabilities

HDL Code Generation
使用HDL Coder™生成用于FPGA和ASIC设计的Verilog和VHDL代码。

Version History

在R2006a之前引入

expand all

Behavior changed in R2019b