9.matlab中repmat函数

来源:

matlab中repmat函数的用法 - CSDN博客

https://blog.csdn.net/anqier1009/article/details/5214978

B = repmat(A,m,n)

B = repmat(A,[m n])
B = repmat(A,[m n p...])

这是一个处理大矩阵且内容有重复时使用,其功能是以A的内容堆叠在(MxN)的矩阵B中,B矩阵的大小由MxN及A矩阵的内容决定,如果A是一个3x4x5的矩阵,有B = repmat(A,2,3)则最后的矩阵是6x12x5

例如:
>>B=repmat( [1 2;3 4],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


其结果变为4X6。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


自己的理解:

就是讲一个矩阵看成是一个元素,repmat(A,3,4)就是将元素A 铺成3*4的矩阵,而A可以是矩阵,数组等

猜你喜欢

转载自blog.csdn.net/luolang_103/article/details/80468799