matrix manipulation, maybe repmat?

1 回表示 (過去 30 日間)
Zoe Zhang
Zoe Zhang 2011 年 7 月 13 日
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 日
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 日
+1: excellent

サインインしてコメントする。

その他の回答 (1 件)

bym
bym 2011 年 7 月 13 日
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 日
Thanks!! Very appreciated!
Andrei Bobrov
Andrei Bobrov 2011 年 7 月 14 日
reshape(permute(a(:,:,[1 1]),[2 3 1]),[],4)'

サインインしてコメントする。

カテゴリ

Help Center および File ExchangeMatrix Indexing についてさらに検索

製品

Community Treasure Hunt

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

Start Hunting!

Translated by