I want to do random swapping in row vector and i know the number of swap to be performed.If row vector x=[1 2 3 4 5 6] the output vector should have unique element with fixed number of swap.
1 visualizzazione (ultimi 30 giorni)
Mostra commenti meno recenti
amit chatterjee
il 10 Mag 2017
Commentato: amit chatterjee
il 22 Mag 2017
swapping of vector should be random.
0 Commenti
Risposta accettata
KL
il 10 Mag 2017
x=[1 2 3 4 5 6]
nSwap = 2;
c = randi(length(x),[nSwap,2])
for i=1:nSwap
x(c(i,:)) = x(fliplr(c(i,:)));
end
x
Più risposte (0)
Vedere anche
Categorie
Scopri di più su Creating and Concatenating Matrices in Help Center e File Exchange
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!