swaping 2 random numbers from array

1 visualización (últimos 30 días)
saphir alexandre
saphir alexandre el 28 de Abr. de 2022
Comentada: saphir alexandre el 28 de Abr. de 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

Respuesta aceptada

Bruno Luong
Bruno Luong el 28 de Abr. de 2022
ij = randperm(length(x)-1,2)+1;
x(ij) = x(flip(ij));
  3 comentarios
Bruno Luong
Bruno Luong el 28 de Abr. de 2022
Simply copy it
y = x;
ij = randperm(length(y)-1,2)+1;
y(ij) = y(flip(ij));
saphir alexandre
saphir alexandre el 28 de Abr. de 2022
thank you

Iniciar sesión para comentar.

Más respuestas (0)

Categorías

Más información sobre Creating and Concatenating Matrices en Help Center y File Exchange.

Etiquetas

Community Treasure Hunt

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

Start Hunting!

Translated by