How to 'unfold' or 'reverse groupcounts?

Hey - is there a way to reverse a groupcount procedure?
I have a two column matrix describing the group number and group occurrence. I would like to convert this cummulative vector to a vector with a row for each occurrence:
[1 2;
2 1;
3 3;
4 1]
I would like to get
[1 1 2 3 3 3 4];
It is essentially reversing groupcounts.
Thanks - Adam

Answers (1)

Bruno Luong
Bruno Luong on 20 Jul 2020
Edited: Bruno Luong on 20 Jul 2020
c = [1 2;
2 1;
3 3;
4 1]
repelem(c(:,1).',c(:,2).')

Categories

Products

Release

R2020a

Asked:

on 20 Jul 2020

Commented:

on 21 Jul 2020

Community Treasure Hunt

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

Start Hunting!