How can I generate a vector that corresponds to counted occurence data?

1 vue (au cours des 30 derniers jours)
Michael Yust
Michael Yust le 25 Août 2021
Commenté : Michael Yust le 25 Août 2021
I am trying to create an array that contains all of the data that I have the counted number of occurences for. For example, if I know the value 5 occurs 2 times, the value 3 occurs 4 times, and the value 1 occurs 6 times, I then want a vector that looks like [5 5 3 3 3 3 1 1 1 1 1 1]. I am wondering if there is a way to create this vector without just manually assigning the values in the array. I am basically trying to recreate a dataset while only having the binned occurence count so that I can run additional statistics on it. Based on my example above what I currently have is two vector that look like [5 3 1] and [2 4 6] and I want the vector shown above.

Réponse acceptée

DGM
DGM le 25 Août 2021
Modifié(e) : DGM le 25 Août 2021
Maybe something like this will work:
A = [5 3 1];
n = [2 4 6];
B = repelem(A,n)
B = 1×12
5 5 3 3 3 3 1 1 1 1 1 1

Plus de réponses (0)

Catégories

En savoir plus sur Logical dans Help Center et File Exchange

Tags

Produits


Version

R2020a

Community Treasure Hunt

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

Start Hunting!

Translated by