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

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

댓글을 달려면 로그인하십시오.

 채택된 답변

Oleg Komarov
Oleg Komarov 2011년 7월 13일

4 개 추천

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개)

bym
bym 2011년 7월 13일

3 개 추천

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

Zoe Zhang
Zoe Zhang 2011년 7월 13일
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 2011년 7월 13일
Thanks!! Very appreciated!
Andrei Bobrov
Andrei Bobrov 2011년 7월 14일
reshape(permute(a(:,:,[1 1]),[2 3 1]),[],4)'

댓글을 달려면 로그인하십시오.

카테고리

도움말 센터 및 File Exchange에서 Matrix Indexing에 대해 자세히 알아보기

제품

Community Treasure Hunt

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

Start Hunting!

Translated by