Repeat numbers of X based on Y to produce Z

2 vues (au cours des 30 derniers jours)
JL
JL le 12 Août 2019
Commenté : Star Strider le 12 Août 2019
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;]

Réponse acceptée

Star Strider
Star Strider le 12 Août 2019
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 commentaires
JL
JL le 12 Août 2019
Thanks!
Star Strider
Star Strider le 12 Août 2019
As always, my pleasure!

Connectez-vous pour commenter.

Plus de réponses (1)

John D'Errico
John D'Errico le 12 Août 2019
help repelem

Catégories

En savoir plus sur Matrices and Arrays dans Help Center et File Exchange

Tags

Community Treasure Hunt

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

Start Hunting!

Translated by