フィルターのクリア

Populate Array with duplicate variables

1 回表示 (過去 30 日間)
Uchenna
Uchenna 2013 年 9 月 18 日
Hi,
I am trying to duplicate the elements within a Matlab array according to the position of elements of the array.
For instance,
x = [1,2,3,4,5,6,4,2,7,5,3] should become x1 = [1,1,2,2,3,3,4,4,5,5,6,6,4,4,2,2,7,7,5,5,3,3]
Thanks

採用された回答

Azzi Abdelmalek
Azzi Abdelmalek 2013 年 9 月 18 日
編集済み: Azzi Abdelmalek 2013 年 9 月 18 日
x = [1,2,3,4,5,6,4,2,7,5,3]
y=[x;x]
y=y(:)'
%Or
n=2
x=repmat(x,n,1);
y=y(:)'
  1 件のコメント
Uchenna
Uchenna 2013 年 9 月 18 日
Thank you very much!

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

その他の回答 (1 件)

Jos (10584)
Jos (10584) 2013 年 9 月 19 日
Another ML-trick:
% data
x = [1 4 3 6] ;
n = 2 ;
% engine
y = kron(x,ones(1,n))

カテゴリ

Help Center および File ExchangeMatrices and Arrays についてさらに検索

Community Treasure Hunt

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

Start Hunting!

Translated by