matrix manipulation, maybe repmat?
1 view (last 30 days)
Show older comments
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 Comments
Accepted Answer
Oleg Komarov
on 13 Jul 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
More Answers (1)
bym
on 13 Jul 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 Comments
See Also
Categories
Find more on Logical in Help Center and File Exchange
Products
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!