필터 지우기
필터 지우기

How do you use randperm on a vector?

조회 수: 9 (최근 30일)
lauuser1
lauuser1 2016년 2월 14일
댓글: Guillaume 2016년 2월 14일
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