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

1 回表示 (過去 30 日間)
Michael Yust
Michael Yust 2021 年 8 月 25 日
コメント済み: Michael Yust 2021 年 8 月 25 日
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 Center および File ExchangeLogical についてさらに検索

タグ

製品


リリース

R2020a

Community Treasure Hunt

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

Start Hunting!

Translated by