changing similar numbers in a raw

1 visualización (últimos 30 días)
nadia nadi
nadia nadi el 3 de Abr. de 2022
Editada: Arif Hoq el 4 de Abr. de 2022
Dear all,
I have a raw with repeated numbers. I want to change them to different onse exactly like the randperm.
X=[1 2 2 2 3 2 4 2 2 2];
i want to make it
X=[1 2 4 3 7 5 8 6 10 9];
many thanks
  1 comentario
KALYAN ACHARJYA
KALYAN ACHARJYA el 3 de Abr. de 2022
Editada: KALYAN ACHARJYA el 3 de Abr. de 2022
X=[1 2 2 2 3 2 4 2 2 2];
Desired result? Any issue?
X=randperm(length(X))
X = 1×10
8 5 1 9 6 4 2 3 7 10

Iniciar sesión para comentar.

Respuestas (2)

nadia nadi
nadia nadi el 3 de Abr. de 2022
Thanks for replying, but i need to keep the numbers 1,3,4 without change their position.
Best

Arif Hoq
Arif Hoq el 4 de Abr. de 2022
Editada: Arif Hoq el 4 de Abr. de 2022
try this:
X=[1 2 2 2 3 2 4 2 2 2];
a=X(X==2);
b=randperm(length(a));
a=b;
X(X==2)=0;
X(X==0)=a
X = 1×10
1 5 6 2 3 7 4 1 4 3

Categorías

Más información sobre Power and Energy Systems 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