MATLAB Answers

How to move values of matrix for 1 out of two rows?

13 views (last 30 days)
MICHEL PHILIPE LIOUSSIS
MICHEL PHILIPE LIOUSSIS on 25 Jan 2020 at 12:54
Commented: Stephen Cobeldick on 25 Jan 2020 at 23:47
Hello, I would like to move to values of a matrix to the next column every two rows. For example:
from 1 0 5 0 to 1 0 5 0
2 0 6 0 0 2 0 6
3 0 7 0 3 0 7 0
4 0 8 0 0 4 0 8
Thanks!

  0 Comments

Sign in to comment.

Answers (1)

Stephen Cobeldick
Stephen Cobeldick on 25 Jan 2020 at 13:04
>> M = [1,0,5,0;2,0,6,0;3,0,7,0;4,0,8,0]
M =
1 0 5 0
2 0 6 0
3 0 7 0
4 0 8 0
>> M(2:2:end,:) = circshift(M(2:2:end,:),1,2)
M =
1 0 5 0
0 2 0 6
3 0 7 0
0 4 0 8

  2 Comments

Stephen Cobeldick
Stephen Cobeldick on 25 Jan 2020 at 23:47
@MICHEL PHILIPE LIOUSSIS: I hope it helped. Please remember to accept my answer if it was useful!

Sign in to comment.

Sign in to answer this question.


Translated by