轉載:https://blog.csdn.net/facetosea1/article/details/83573859
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
