Given a vector
SP = [1 2 4 5 8 11 13 14 15 16 18 19 20];
I want to create random sequence based on the vector
Y = [4 24 35 8 9 20 42 40 12 13 49 22 32];
It means that in the random sequnce I want element one repeated 4 times, element 2 repeated 24 times, element 4 repeated 35 times, element 5 repeated 8 times, element 8 repeated 9 times and so on.
Hence, the length of the final sequence will be equal to the cumulative sum of Y
4 + 24 + 35 + 8 + 9 + 20 + 42 + 40 + 12 + 13 + 49 + 22 + 32 = 310

 채택된 답변

madhan ravi
madhan ravi 2019년 9월 12일
편집: madhan ravi 2019년 9월 12일
v = repelem(SP,Y);
W = v(randperm(numel(v))) % numel(W)

댓글 수: 2

luca
luca 2019년 9월 12일
May you kindly explain how it works?
help repelem
help randperm

댓글을 달려면 로그인하십시오.

추가 답변 (0개)

카테고리

도움말 센터 및 File Exchange에서 Random Number Generation에 대해 자세히 알아보기

제품

릴리스

R2019a

질문:

2019년 9월 12일

댓글:

2019년 9월 12일

Community Treasure Hunt

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

Start Hunting!

Translated by