matrix manipulation, maybe repmat?

1 vue (au cours des 30 derniers jours)
Zoe Zhang
Zoe Zhang le 13 Juil 2011
I have a huge matrix, just to make the case simple
Say I have a =
1 4 7 10
2 5 8 11
And I would like to get: a =
1 4 7 10
1 4 7 10
2 5 8 11
2 5 8 11
Is there a smart way of doing that(without loop)?
Thanks in advance!!
  2 commentaires
Oleg Komarov
Oleg Komarov le 13 Juil 2011
5000 * 4 * (8 bytes) = 0.152587891 megabytes: not so huge.
Zoe Zhang
Zoe Zhang le 13 Juil 2011
Agreed and thanks~

Connectez-vous pour commenter.

Réponse acceptée

Oleg Komarov
Oleg Komarov le 13 Juil 2011
Dynamic version of the solution proposed by proecsm:
n = 2;
idx = repmat(1:size(a,1),n,1);
b = a(idx(:),:)
or
kron(A,ones(n,1))
or
  1 commentaire
bym
bym le 13 Juil 2011
+1: excellent

Connectez-vous pour commenter.

Plus de réponses (1)

bym
bym le 13 Juil 2011
a =
1 4 7 10
2 5 8 11
>> b = a([1,1,2,2],:)
b =
1 4 7 10
1 4 7 10
2 5 8 11
2 5 8 11
  3 commentaires
Zoe Zhang
Zoe Zhang le 13 Juil 2011
Thanks!! Very appreciated!
Andrei Bobrov
Andrei Bobrov le 14 Juil 2011
reshape(permute(a(:,:,[1 1]),[2 3 1]),[],4)'

Connectez-vous pour commenter.

Catégories

En savoir plus sur Logical dans Help Center et File Exchange

Produits

Community Treasure Hunt

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

Start Hunting!

Translated by