swaping 2 random numbers from array

1 次查看(过去 30 天)
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));

更多回答(0 个)

类别

Help CenterFile Exchange 中查找有关 Random Number Generation 的更多信息

标签

Community Treasure Hunt

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

Start Hunting!

Translated by