I need to count the numbers from a vector to form a new vector, so I need to use (2, 3, 1) to get (1, 1, 2, 2, 2, 3). How do I do this?

1 view (last 30 days)
I have a vector which contains the values of the degrees for each node, so nodes (1, 2, 3) have degree (2, 3, 1) respectively. I want a new vector which stores the nodes as many times as the degree for that node is. So for the nodes and degrees above I will get a vector (1, 1, 2, 2, 2, 3).

Accepted Answer

Adam
Adam on 17 Jul 2017
repelem( 1:3, [2 3 1] )
should work.

More Answers (0)

Tags

Community Treasure Hunt

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

Start Hunting!