How to "restart" a matrix from an especific element

Hi everyone. I have a square matrix like this: [1,2,3;4,5,6;7,8,9]
How could I restart the sequence from an especific element? For example, I want to restart the sequence from 4, so the matrix will be: [1,2,3;4,1,2;3,4,5]
Thanks a lot!

 Accepted Answer

restart_after := 4;
Matrix(restart_after+1:end) = Matrix(1:end-restart_after);

1 Comment

Thanks. But that works when the matrix is ordered by columns. If the sequence is sorted by rows, like the example, don't.

Sign in to comment.

More Answers (0)

Community Treasure Hunt

Find the treasures in MATLAB Central and discover how the community can help you!

Start Hunting!