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 Center および File ExchangeCreating and Concatenating Matrices についてさらに検索

タグ

Community Treasure Hunt

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

Start Hunting!

Translated by