swaping 2 random numbers from array
2 vues (au cours des 30 derniers jours)
Afficher commentaires plus anciens
saphir alexandre
le 28 Avr 2022
Commenté : saphir alexandre
le 28 Avr 2022
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
0 commentaires
Réponse acceptée
Bruno Luong
le 28 Avr 2022
ij = randperm(length(x)-1,2)+1;
x(ij) = x(flip(ij));
3 commentaires
Bruno Luong
le 28 Avr 2022
Simply copy it
y = x;
ij = randperm(length(y)-1,2)+1;
y(ij) = y(flip(ij));
Plus de réponses (0)
Voir également
Catégories
En savoir plus sur Random Number Generation dans Help Center et File Exchange
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!