How do you use randperm on a vector?

13 views (last 30 days)
lauuser1
lauuser1 on 14 Feb 2016
Commented: Guillaume on 14 Feb 2016
I have a vector
A = repmat(1:6, [1 4])
and I need to use randperm to randomize it. How would I do that?

Accepted Answer

Kristi
Kristi on 14 Feb 2016
A = repmat(1:6, [1 4])
B = A(randperm(24))
  1 Comment
Guillaume
Guillaume on 14 Feb 2016
B = A(randperm(numel(A))
would be a lot better since it will work regardless of the size of A. As a rule avoid hardcoded constants, particularly as it's trivial to obtain the number of elements in A.

Sign in to comment.

More Answers (0)

Categories

Find more on Creating and Concatenating Matrices in Help Center and File Exchange

Community Treasure Hunt

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

Start Hunting!