Repeat numbers of X based on Y to produce Z

2 ビュー (過去 30 日間)
JL
JL 2019 年 8 月 12 日
コメント済み: Star Strider 2019 年 8 月 12 日
I have 2 matrices, X and Y, and using these 2 matrices I would like to produce a third one called Z.
X = [1; 2; 3; 4; 5;]
Y = [3; 1; 4; 2; 2;]
where in Z, the numbers in X are repeated based on X
Z = [1;
1;
1;
2;
3;
3;
3;
3;
4;
4;
5;
5;]

採用された回答

Star Strider
Star Strider 2019 年 8 月 12 日
Use the repelem function (R2015a and later):
Z = repelem(X, Y)
producing:
Z =
1
1
1
2
3
3
3
3
4
4
5
5
  2 件のコメント
JL
JL 2019 年 8 月 12 日
Thanks!
Star Strider
Star Strider 2019 年 8 月 12 日
As always, my pleasure!

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

その他の回答 (1 件)

John D'Errico
John D'Errico 2019 年 8 月 12 日
help repelem

カテゴリ

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