How to duplicate a 2000 x 200 matrix n times

17 views (last 30 days)
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,

Accepted Answer

Alex Mcaulley
Alex Mcaulley on 27 Mar 2019
Try this:
repmat(A,60,1)
Is it that you want?
  4 Comments
John D'Errico
John D'Errico on 27 Mar 2019
Edited: John D'Errico on 27 Mar 2019
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 on 27 Mar 2019
@Alex and @ John
Thank you very much for such an elaboaration. It clarifies me the use of repmat as well.
Thanks,

Sign in to comment.

More Answers (1)

Jan
Jan on 27 Mar 2019
Edited: Jan on 27 Mar 2019
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.

Tags

Community Treasure Hunt

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

Start Hunting!