Create a sequence that take into account two arrays
조회 수: 1 (최근 30일)
이전 댓글 표시
Given the arrays
SP = [1 2 4 6 7 9 10]
V = [5 20 10 15 5 20 10 ]
I want to create a random array P that contain the elements of SP repeated as many times as is indicated in V. So the element one has to be repeated 5 times, two repeated 20 times, four repeated 10 times and so on.
A basic rule has to be respected in the array: the element in position "i" may enter in the created sequence just when the number of precedence elements minus one are completed. This mean for example that 6, that is in position 4, may enter in the sequence when the number of precedence element (e.g 3, that are 1 2 and 4) minus one are completed . That is, 6 can enter once 2 elements between 1 2 and 4 are already in the sequence as many times as indicated in V
Considering another element: 9 must enter in the sequence when 4 out 5 of its previous elements are completed. That is, if 4 elements between 1,2,4,6,7 are already in the sequence as many times as indicated in V, I can activate 9 and put inside the sequence also 9.
a random example could be :
P = [1 1 2 1 2 1 2 2 1 2 2 4 2 4 2 4 2 4 4 2 2 4 2 2 4 4 2 2 4 4 2 6 2 6 2 6 6 2 6 2 6 6 7 6 7 7 6 6 7 6 6 7 6 9 6 9 6 9 9 10 10 9 9 10 9 9 10 9 9 10 9 9 10 9 9 10 9 9 10 10 9 9 10 9 9]
I don't know if it's possible to create a random sequence and ordinate on the basis on the last rule, or if it's better to generate the sequence directly considering the rule.
May someone help me with this task?
답변 (0개)
참고 항목
카테고리
Help Center 및 File Exchange에서 Creating and Concatenating Matrices에 대해 자세히 알아보기
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!