Reputation: 95
set of 30 numbers that have been stored inside a vector d
for example.
d = [ 3 5 7 2 7 8 .....]
However the numbers inside will shuffled around constantly for a few hundred iterations.
The following is what is used to shuffle the numbers
i = randperm(length(d));
d = d(i);
using a loop to shuffle it as many times as is needed to.
Is there a method to store or record all the different results of the shuffle and to be able to view the contents later?
For example, having the need to check what was the arrangement of the 37th
shuffle and compare it with the 45th
.
The amount of numbers stored inside "d"
could changed depending on circumstance..
sorry for my weak understanding of this subject. Appreciated any help in this matter..
Upvotes: 3
Views: 49
Reputation: 2328
You can store them in a matrix, where each row represent a single permutation.
d = [original number vector];
num = number of random permutations needed;
perms = zeros(num, len(d));
perms(1, :) = d;
for i = 2:num
p = randperm(len(d));
prerms(i, :) = perms(i-1, p);
Upvotes: 2
Reputation: 383
You can save the results by saving them in a matrix.
Start with s = d
.
Then after each iteration, you can append s
with
s = [s ; d];
If you want to view the 2nd iteration afterwards, type s(2,:)
.
Upvotes: 2