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

1 view (last 30 days)
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.

Accepted Answer

DGM
DGM on 25 Aug 2021
Edited: DGM on 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

More Answers (0)

Tags

Products


Release

R2020a

Community Treasure Hunt

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

Start Hunting!