user3150845
user3150845

Reputation: 95

How to store a few hundred sets of generated vectors and to be able to pull out and observe their contents later on?

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

Answers (2)

Buddhima Gamlath
Buddhima Gamlath

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

mvdnes
mvdnes

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

Related Questions