Repeat every element in matrix

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

2 个评论

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.

请先登录,再进行评论。

 采纳的回答

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))';
(Corrected)

4 个评论

Thank you very much.. I want to repeat each row (200) times I mean 0 0 0 (first row) 0 0 0 0 0 0 0 0 0 to 200 times so should I use
A = reshape(repmat(reshape(A',[],1),[],*200*)',9,[])'; ??
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))';

请先登录,再进行评论。

更多回答(0 个)

类别

帮助中心File Exchange 中查找有关 Matrix Indexing 的更多信息

Community Treasure Hunt

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

Start Hunting!

Translated by