matrix manipulation, maybe repmat?

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 Kommentare

Oleg Komarov
Oleg Komarov am 13 Jul. 2011
5000 * 4 * (8 bytes) = 0.152587891 megabytes: not so huge.
Zoe Zhang
Zoe Zhang am 13 Jul. 2011
Agreed and thanks~

Melden Sie sich an, um zu kommentieren.

 Akzeptierte Antwort

Oleg Komarov
Oleg Komarov am 13 Jul. 2011

4 Stimmen

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

Weitere Antworten (1)

bym
bym am 13 Jul. 2011

3 Stimmen

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 Kommentare

Zoe Zhang
Zoe Zhang am 13 Jul. 2011
Yes, this is what I want. But actually my matrix is 5000*4, how would you suggest I do the same thing? Thanks a lot!
Zoe Zhang
Zoe Zhang am 13 Jul. 2011
Thanks!! Very appreciated!
Andrei Bobrov
Andrei Bobrov am 14 Jul. 2011
reshape(permute(a(:,:,[1 1]),[2 3 1]),[],4)'

Melden Sie sich an, um zu kommentieren.

Kategorien

Produkte

Community Treasure Hunt

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

Start Hunting!

Translated by