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

조회 수: 1 (최근 30일)
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.

채택된 답변

DGM
DGM 2021년 8월 25일
편집: DGM 2021년 8월 25일
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

추가 답변 (0개)

카테고리

Help CenterFile Exchange에서 Logical에 대해 자세히 알아보기

태그

제품


릴리스

R2020a

Community Treasure Hunt

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

Start Hunting!

Translated by