Azzera filtri
Azzera filtri

Repeat every element in matrix

2 visualizzazioni (ultimi 30 giorni)
Ahmed Hussein
Ahmed Hussein il 28 Giu 2013
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 Commenti
per isakson
per isakson il 28 Giu 2013
row-wise or column-wise?
Ahmed Hussein
Ahmed Hussein il 28 Giu 2013
Modificato: Ahmed Hussein il 28 Giu 2013
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.

Accedi per commentare.

Risposta accettata

Roger Stafford
Roger Stafford il 28 Giu 2013
Modificato: Roger Stafford il 28 Giu 2013
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 Commenti
Ahmed Hussein
Ahmed Hussein il 28 Giu 2013
Thanks a lot, it is very useful.....
Roger Stafford
Roger Stafford il 29 Giu 2013
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))';

Accedi per commentare.

Più risposte (0)

Categorie

Scopri di più su Creating and Concatenating Matrices in Help Center e File Exchange

Community Treasure Hunt

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

Start Hunting!

Translated by