matlab矩阵复制函数:【repmat】

本文详细介绍了 MATLAB 中的 repmat 函数,该函数用于复制和平铺矩阵。文章通过多个示例展示了如何使用 repmat 来创建特定结构的大矩阵,并讨论了不同输入参数下 repmat 的行为。

摘要生成于 C知道 ,由 DeepSeek-R1 满血版支持, 前往体验 >

repmat 即 Replicate Matrix ,复制和平铺矩阵,是 MATLAB 里面的一个函数。

B = repmat(A,m,n)            %将矩阵A复制m×n块,即B由m×n块A平铺而成

B = repmat(A,[m n])          %与上面一致

B = repmat(A,[m n p...])    %B由m×n×p×…个A块平铺而成

repmat(A,m,n)                   %当A是一个数a时,该命令产生一个全由a组成的m×n矩阵。

处理大矩阵且内容有重复时使用,其功能是以A的内容堆叠在(MxN)的矩阵B中,B矩阵的大小由MxN及A矩阵的内容决定

如果A是一个3x4x5的矩阵,有B = repmat(A,2,3)则最后的矩阵是6x12x5。

一、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)).


例如:

一、B = repmat(A,m,n)
将矩阵 A 复制 m×n 块,即把 A 作为 B 的元素,B 由 m×n 个 A 平铺而成。B 的维数是 [size(A,1)*m, size(A,2)*n] 。
>> A = [1,2;3,4]
A =
1 2
3 4
>> B = repmat(A,2,3)
B =
1 2 1 2 1 2
3 4 3 4 3 4
1 2 1 2 1 2
3 4 3 4 3 4
二、B = repmat(A,[m n])
与 B = repmat(A,m,n) 用法一致。
三、B = repmat(A,[m n p...])
B 是由 m×n×p×… 个 A 平铺而成的高维数组。B 的维数是 [size(A,1)*m, size(A,2)*n, size(A,3)*p, ...] 。
>> A =  eye(2,2)
A =
1 0
0 1
>> B = repmat(A,[2 3 2])
B(:,:,1) =
1 0 1 0 1 0
0 1 0 1 0 1
1 0 1 0 1 0
0 1 0 1 0 1
B(:,:,2) =
1 0 1 0 1 0
0 1 0 1 0 1
1 0 1 0 1 0
0 1 0 1 0 1


>>temp=1:10;

>>a=repmat(temp,10,1)

a = 1 2 3 4 5 6 7 8 9 10 1 2 3 4 5 6 7 8 9 10 1 2 3 4 5 6 7 8 9 10 1 2 3 4 5 6 7 8 9 10 1 2 3 4 5 6 7 8 9 10 1 2 3 4 5 6 7 8 9 10 1 2 3 4 5 6 7 8 9 10 1 2 3 4 5 6 7 8 9 10 1 2 3 4 5 6 7 8 9 10 1 2 3 4 5 6 7 8 9 10

>> b=repmat(temp',1,10)

b = 1 1 1 1 1 1 1 1 1 1 2 2 2 2 2 2 2 2 2 2 3 3 3 3 3 3 3 3 3 3 4 4 4 4 4 4 4 4 4 4 5 5 5 5 5 5 5 5 5 5 6 6 6 6 6 6 6 6 6 6 7 7 7 7 7 7 7 7 7 7 8 8 8 8 8 8 8 8 8 8 9 9 9 9 9 9 9 9 9 9 10 10 10 10 10 10 10 10 10 10

A也可以置放文字串,如:

>>C=repmat(' Long live the king!', 2,2)
C =
Long live the king! Long live the king!
Long live the king! Long live the king!

也可置放其他的

>> D=repmat(NaN,2,5)
D =
NaN   NaN   NaN   NaN   NaN
NaN   NaN   NaN   NaN   NaN

评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值