replicate values of a vector

3 ビュー (過去 30 日間)
antonet
antonet 2012 年 5 月 23 日
Dear all,
I have, say the vector A=(1:12)'; and I want to replicate each of the 12 numbers 4 times. Any simple code for this?
thanks in advance

採用された回答

Friedrich
Friedrich 2012 年 5 月 23 日
Hi,
try repmat:
repmat(A,4,1)
Or for the other direction:
repmat(A,1,4)
In the case you want it repeated like this: [1 1 1 1 2 2 2 2 ....] you can use repmat and reshape:
reshape(repmat(A,4,1),[],1)
  2 件のコメント
antonet
antonet 2012 年 5 月 23 日
thank you friedrich!
Andrei Bobrov
Andrei Bobrov 2012 年 5 月 23 日
kron(A,ones(4,1))

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

その他の回答 (0 件)

カテゴリ

Help Center および File ExchangeCreating and Concatenating Matrices についてさらに検索

Community Treasure Hunt

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

Start Hunting!

Translated by