How to change the elements's position of a vector by N consecutive times?
2 visualizaciones (últimos 30 días)
Mostrar comentarios más antiguos
vinicius lanziotti
el 7 de Dic. de 2017
Comentada: vinicius lanziotti
el 7 de Dic. de 2017
I want a loop that executes at one time only several combinations.
x = [1 2 3 4 5];
xp = randperm(numel(x), 2);
x(xp) = x(fliplr(xp))
>> test
x =
1 2 4 3 5
>> test
x =
1 3 2 4 5
0 comentarios
Respuesta aceptada
Image Analyst
el 7 de Dic. de 2017
Can't you simply use a for loop???
for k = 1 : N
test
end
or you can use deal to do the swapping of indexes:
[x(xp(1)), x(xp(2))] = deal(x(xp(2)), x(xp(1)));
Más respuestas (0)
Ver también
Categorías
Más información sobre Matrix Indexing en Help Center y File Exchange.
Productos
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!