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

1 Ansicht (letzte 30 Tage)
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.

Akzeptierte Antwort

DGM
DGM am 25 Aug. 2021
Bearbeitet: DGM am 25 Aug. 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

Weitere Antworten (0)

Tags

Produkte


Version

R2020a

Community Treasure Hunt

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

Start Hunting!

Translated by