Random shuffle of vector elements
이전 댓글 표시
Hello,
How to randomly shuffle all elements of the vector except the first and last position?
For example:
I have vector A=[5 1.5 1.6 1.7 5] and I want to randomly shuffle 2nd, 3rd 4th element while the 1st and the last will stay the same.
Thank you
채택된 답변
추가 답변 (1개)
Fangjun Jiang
2021년 10월 5일
p=randperm(3);
index=[1,1+p,5];
b=A(index);
댓글 수: 1
Fangjun Jiang
2021년 10월 5일
do it in one shot
p=perms(2:4);
index=[ones(6,1), p, 5*ones(6,1)];
b=A(index)
카테고리
도움말 센터 및 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!