How to pseudo-randomize the ordering of a vector?

10 Ansichten (letzte 30 Tage)
Paul Scotti
Paul Scotti am 22 Nov. 2017
Beantwortet: Jeff Miller am 22 Nov. 2017
Say that I have a vector
A=randperm(10)
and I want to randomize the ordering of this vector. Normally I would do something like
A=Shuffle(A)
but in this case I want a pseudoradomized ordering: that is, the later the value is in A (ordering wise, not the actual content of the value), the more I want it to appear near the beginning of A. For instance, I want there to be a greater chance of values A(7:10) to appear near the front of A and the values A(1:4) to appear near the end of A. Hopefully that makes sense.
Is this possible to do?

Akzeptierte Antwort

Jeff Miller
Jeff Miller am 22 Nov. 2017
One approach is to think of your data, A, as being column one of a 2-column array (e.g., 10x2). Now generate pseudo-random numbers into column 2 using some scheme that tends to give smaller values to higher numbered rows, e.g.,
for iRow=1:NRows
A(iRow,2) = normrnd(-iRow,1);
end
Then, sort the rows of A by the random numbers, carrying along the data values in column 1 (see, for example, https://stackoverflow.com/questions/134712/how-can-i-sort-a-2-d-array-in-matlab-with-respect-to-one-column).
Obviously you have a lot of choices for how to assign the numbers, depending on exactly how biased you want your pseudo-random ordering to be.

Weitere Antworten (0)

Kategorien

Mehr zu Creating and Concatenating Matrices finden Sie in Help Center und File Exchange

Community Treasure Hunt

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

Start Hunting!

Translated by