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?

2 visualizzazioni (ultimi 30 giorni)
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).

Risposta accettata

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

Più risposte (0)

Categorie

Scopri di più su Operating on Diagonal Matrices in Help Center e File Exchange

Tag

Community Treasure Hunt

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

Start Hunting!

Translated by