How to duplicate a 2000 x 200 matrix n times

17 次查看(过去 30 天)
Dear
I have a matrix of size 2000 x 200 double. I am looking forward to duplicate this matrix 60 times as it is.
So if the matrix A is like
A=[1 2 3;4 5 6] and if I repeat it 2 times it must be like A=[1 2 3; 4 5 6; 1 2 3; 4 5 6; 1 2 3 ; 4 5 6]
I have tried to do this like
repmat(A,60,200);.
But it is producing the following error:
Error using repmat
Requested 6705122x31684 (1582.8GB) array exceeds maximum array size preference. Creation of arrays greater than this limit may take a long time and cause MATLAB to become unresponsive. See array size limit or preference panel for more information.
Would you please show me the suitable way to duplicate the matrix?
Thanks,

采纳的回答

Alex Mcaulley
Alex Mcaulley 2019-3-27
Try this:
repmat(A,60,1)
Is it that you want?
  4 个评论
John D'Errico
John D'Errico 2019-3-27
编辑:John D'Errico 2019-3-27
To respond, suppose you created a simple 2x2 array, then did this:
A = ones(2,2);
size(repmat(A,3,4))
ans =
6 8
In this example, repmat replicates the first dimension here by 3. And the second dimension gets replicated by 4.
By extension, all you wanted to do was to replicate the matrix 60 times, just adding extra rows to the matrix. You wanted to leave the columns unchanged.
If you leave out the 1 completely, just use repmat(A,3), this happens:
size(repmat(A,3))
ans =
6 6
So both the rows and columns of A get replicated there.
Ergo the 1.
Saugata Bose
Saugata Bose 2019-3-27
@Alex and @ John
Thank you very much for such an elaboaration. It clarifies me the use of repmat as well.
Thanks,

请先登录,再进行评论。

更多回答(1 个)

Jan
Jan 2019-3-27
编辑:Jan 2019-3-27
You mean:
repmat(A, 61, 1)
In your example, you have "repeated" the input [2 x 3] matrix to the output [3 x 3] and call thims "2 times", so I assume you want 61 copies of the origibnal matrix.
Your code repmat(A,60,200) would repeat A "59" times horizontally and "199" times vertically.
By the way, you want to create a [2000 * 61 x 200] matrix. If this has the type double, it requires 192 MB.

类别

Help CenterFile Exchange 中查找有关 Logical 的更多信息

标签

Community Treasure Hunt

Find the treasures in MATLAB Central and discover how the community can help you!

Start Hunting!

Translated by