Effacer les filtres
Effacer les filtres

Duplicating columns into a matrix

90 vues (au cours des 30 derniers jours)
Alexander Engman
Alexander Engman le 22 Mar 2018
Modifié(e) : Jan le 22 Mar 2018
Hi!
I think this is very easy to solve, but I simply dont know what is the easiest way. Let's say I have a vector:
A=[1 2 3]
Now I want to repeat this column into a Matrix
B=[1 2 3; 1 2 3; 1 2 3]
How do I go about this?
Thanks in advance.
Alexander

Réponse acceptée

Birdman
Birdman le 22 Mar 2018
B=repmat(A,3,1)
  1 commentaire
Alexander Engman
Alexander Engman le 22 Mar 2018
Yepp. Thanks a lot!

Connectez-vous pour commenter.

Plus de réponses (1)

Jan
Jan le 22 Mar 2018
Modifié(e) : Jan le 22 Mar 2018
Or:
B = A(ones(1,3), :)
This is what happens inside repmat also. It has slightly less overhead, but I'd prefer repmat instead - for unclear reasons.

Catégories

En savoir plus sur Matrix Indexing dans Help Center et File Exchange

Community Treasure Hunt

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

Start Hunting!

Translated by