Question

I tried figuring this out but it doesn't work.

Say I have

a = [5,1,5,6,7,2,4];

Now, if I do a(randperm(a)) i get :

ans =

     1     7     6     5     5

Now, I also have

b = [1,2,3,4,5,6,7,8,9,10];

However, if I do b(randperm(b)) :

ans =

     1

Why is this happening? This does not seem to make any sense to me. How do I shuffle a vector like :

z = [1,2,3,4.... 1500,6001,6002,6003... 8999];
Was it helpful?

Solution

randperm takes a single N and returns a permutation of the numbers 1 to N.

I don't have Matlab installed so I can't try this out, but this should work:

a(randperm(length(a)))

OTHER TIPS

The parameter of randperm should not be the array but it's length. Try

B(randperm(length(B)))
Licensed under: CC-BY-SA with attribution
Not affiliated with StackOverflow
scroll top