How do you use randperm on a vector?

7 次查看(过去 30 天)
I have a vector
A = repmat(1:6, [1 4])
and I need to use randperm to randomize it. How would I do that?

采纳的回答

Kristi
Kristi 2016-2-14
A = repmat(1:6, [1 4])
B = A(randperm(24))
  1 个评论
Guillaume
Guillaume 2016-2-14
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.

请先登录,再进行评论。

更多回答(0 个)

类别

Help CenterFile Exchange 中查找有关 Structures 的更多信息

Community Treasure Hunt

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

Start Hunting!

Translated by