How to move an element from an array?
Mostrar comentarios más antiguos
I have an array and i want to to move the element a which located in x line, by one position to the right without change the left part
3 comentarios
Guillaume
el 5 de Sept. de 2017
Can you provide an example of before and after?
GEORGIOS KOULIDIS
el 5 de Sept. de 2017
Editada: Stephen23
el 6 de Sept. de 2017
Pal Szabo
el 6 de Sept. de 2017
If you have this as original array:
A=[ 1 2 3 4 0 0 0;
5 3 2 1 0 0 0;
4 4 4 4 0 0 0;
2 3 4 5 6 7 8]
You want to move the elements starting from line row=2, column=3 (this is your number two), and replace the element originally in position row=2 column=3 by another element stored in the variable replacewith (in this case 0), then write:
A=[ 1 2 3 4 0 0 0;
5 3 2 1 0 0 0;
4 4 4 4 0 0 0;
2 3 4 5 6 7 8]
x=2
y=3
replacewith=0;
result_xth_row=[A(x,1:y-1),replacewith,A(x,y:end-1)]
A(x,1:end)=result_xth_row
A
Respuesta aceptada
Más respuestas (1)
Andrei Bobrov
el 5 de Sept. de 2017
A(2,3:end) = circshift(A(2,3:end),1)
1 comentario
GEORGIOS KOULIDIS
el 5 de Sept. de 2017
Categorías
Más información sobre Creating and Concatenating Matrices en Centro de ayuda y File Exchange.
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!