How to move an element from an array?
Mostra commenti meno recenti
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 Commenti
Guillaume
il 5 Set 2017
Can you provide an example of before and after?
GEORGIOS KOULIDIS
il 5 Set 2017
Modificato: Stephen23
il 6 Set 2017
Pal Szabo
il 6 Set 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
Risposta accettata
Più risposte (1)
Andrei Bobrov
il 5 Set 2017
A(2,3:end) = circshift(A(2,3:end),1)
1 Commento
GEORGIOS KOULIDIS
il 5 Set 2017
Categorie
Scopri di più su Creating and Concatenating Matrices in Centro assistenza e File Exchange
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!