randperm and sorting array
조회 수: 9 (최근 30일)
이전 댓글 표시
as example :
A = [8 9 0]
Perm1 = randperm(length(A));
B= A(:,Perm1);
B_eks=B
[val_sort, id_sort] = sort(Perm1);
A_eks = B_eks(:,id_sort);
i want it for looping, so A_eks(:,:,1) = [8 9 0],;A_eks(:,:,2) = [8 9 0],A_eks(:,:,2) = [8 9 0],A_eks(:,:,4) = [8 9 0], i have try like this:
for i=1:4
Perm1(:,:,i) = randperm(length(A));
B(:,:,i)= A(:,Perm1(:,:,i));
B_eks(:,:,i)=B(:,:,i)
end
for k=1:4
[val_sort, id_sort] = sort(Perm1(:,:,k));
A_eks(:,:,k) = B_eks(:,id_sort);
end
but it didn't work like i want, what should i do ?
댓글 수: 6
KSSV
2017년 10월 25일
If you want it to be same..keep it same....why to run all the stuff? Using randperm is good if you want to permute array randomly.
채택된 답변
추가 답변 (0개)
참고 항목
카테고리
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!