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 CenterFile Exchange에서 Matrices and Arrays에 대해 자세히 알아보기

태그

Community Treasure Hunt

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

Start Hunting!

Translated by