Create a random sequence with specified values
Ältere Kommentare anzeigen
Given a matrix
A= [0 15 11 2 4 0 3 1 13;
14 0 16 0 0 0 0 0 0;
0 0 0 0 8 0 0 0 0;
0 0 18 0 0 0 0 0 0;
0 0 19 0 0 0 0 0 0;
0 0 0 0 0 0 0 0 0];
I want to create a random sequence in a vector F where
1) the sequence that I need to create must be composed by a repetition of batches. The elements inside the batches are defined by each columns: The 1st batch is made by 14. the 2nd batch is made by 15. the 3rd batch is made by 11 16 18 19 and so on.
The length of the batches should be variable.
2) given a vector S = [1 2 3 4 8 11 13 14 15 16 18 19 20] which collects the elements in A and a vector Y= [ 12 34 45 10 12 35 40 40 23 45 21 24 56], Y tells us how many parts we need inside the sequence. So we need part-1 12 times, part-2 34 times, part-3 45 times, part-4 10 times and so on. in total the sequence will have length equal to sum(Y)=397
May someone help me with this difficult task?
3 Kommentare
the cyclist
am 16 Sep. 2019
I don't fully understand the procedure.
S(1) equals 1. (That points me to the 7th column of A, right?) I need to generate 12 "parts", because, because Y(1) equals 12. Right?
How should those 12 "parts" be generated? I assume something involving randomness, since you said you want a random sequence. Do you want to randomly select values from the 7th column of A? So, mostly zeros, but sometimes the value 1?
Maybe if you gave a smaller example, you could step through what the algorithm should do explicitly, with an example of the output.
Guillaume
am 16 Sep. 2019
Other than S being sort(nonzeros(A))' with a 20 tacked on the end for some reason, I don't see how the second half of the question is related the the first half. In particular, in the 2nd half, it's not clear what parts refer to in "how many parts we need. Are the parts somehow related to the batches of the 1st half.
Antworten (0)
Kategorien
Mehr zu Creating and Concatenating Matrices finden Sie in Hilfe-Center und File Exchange
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!