randperm
조회 수: 26 (최근 30일)
이전 댓글 표시
How can I use randperm for a nx2 matrix?
댓글 수: 1
Dr. Seis
2011년 11월 11일
"randperm" only takes 1 scalar input argument. Can you give a sample of an input nx2 matrix AND what you would expect the output to be?
답변 (3개)
Jonathan
2011년 11월 11일
If you want to randomly permute the rows, do something like the following.
n = 5;
A = reshape(1:2*n, n, 2)
B = A(randperm(n), :)
If you want to randomly permute all elements, do something like this instead.
C = reshape(A(randperm(2*n)), n, 2)
댓글 수: 1
Jonathan
2011년 11월 11일
@Miriam, to permute the columns separately do this.
D = A;
D(:,1) = D(randperm(n),1);
D(:,2) = D(randperm(n),2);
참고 항목
카테고리
Help Center 및 File Exchange에서 Creating and Concatenating Matrices에 대해 자세히 알아보기
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!