swaping 2 random numbers from array

조회 수: 1 (최근 30일)
saphir alexandre
saphir alexandre 2022년 4월 28일
댓글: saphir alexandre 2022년 4월 28일
hello,
I have an array x = [1,(randperm(20)+1)]
but i would like to swap 2 random numbers of that array while keeping 1 as my first integer
please let me know how to go about that

채택된 답변

Bruno Luong
Bruno Luong 2022년 4월 28일
ij = randperm(length(x)-1,2)+1;
x(ij) = x(flip(ij));
  댓글 수: 3
Bruno Luong
Bruno Luong 2022년 4월 28일
Simply copy it
y = x;
ij = randperm(length(y)-1,2)+1;
y(ij) = y(flip(ij));
saphir alexandre
saphir alexandre 2022년 4월 28일
thank you

댓글을 달려면 로그인하십시오.

추가 답변 (0개)

카테고리

Help CenterFile Exchange에서 Creating and Concatenating Matrices에 대해 자세히 알아보기

태그

Community Treasure Hunt

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

Start Hunting!

Translated by