MATLAB Answers

Ahmed Hussein

Repeat every element in matrix

Asked by Ahmed Hussein
on 28 Jun 2013


I have a matrix A(3200,3), I want to repeat each element (not repeat the matrix)in this matrix 200 times.

Thank you


row-wise or column-wise?

A=[0 0 0 I want A to be A=[ 0 0 0 0 0 0 . 0 0 0 . . . . and so on to 200 times then the second element and so on.


No products are associated with this question.

1 Answer

Answer by Roger Stafford
on 28 Jun 2013
Edited by Roger Stafford
on 28 Jun 2013
 Accepted answer

 A = reshape(repmat(A(:)',200,1),[],3);

This repeats the elements in the columns. If you want to repeat the along the rows do this:

 A = reshape(repmat(reshape(A',[],1),1,200)',[],size(A,1))';



No, don't use that one. I corrected it to:

 A = reshape(repmat(reshape(A',[],1),1,200)',[],size(A,1))';

(I had a senior moment.)

Thanks a lot, it is very useful.....

That code I gave you has one more transpose than is necessary. You can do it this way instead:

 A = reshape(repmat(reshape(A',1,[]),200,1),[],size(A,1))';

Join the 15-year community celebration.

Play games and win prizes!

Learn more
Discover MakerZone

MATLAB and Simulink resources for Arduino, LEGO, and Raspberry Pi

Learn more

Discover what MATLAB® can do for your career.

Opportunities for recent engineering grads.

Apply Today

MATLAB Academy

New to MATLAB?

Learn MATLAB today!