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 Ansicht (letzte 30 Tage)
Ältere Kommentare anzeigen
amit chatterjee
am 10 Mai 2017
Kommentiert: amit chatterjee
am 22 Mai 2017
swapping of vector should be random.
0 Kommentare
Akzeptierte Antwort
KL
am 10 Mai 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
Weitere Antworten (0)
Siehe auch
Kategorien
Mehr zu Creating and Concatenating Matrices finden Sie in Help Center und File Exchange
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!