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 (최근 30일)
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).

채택된 답변

Adam
Adam 2017년 7월 17일
repelem( 1:3, [2 3 1] )
should work.

추가 답변 (0개)

카테고리

Help CenterFile Exchange에서 Operating on Diagonal Matrices에 대해 자세히 알아보기

태그

Community Treasure Hunt

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

Start Hunting!

Translated by