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

1 次查看(过去 30 天)
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!

回答(1 个)

Stephen23
Stephen23 2020-1-25
>> 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

类别

Help CenterFile Exchange 中查找有关 Matrix Indexing 的更多信息

Community Treasure Hunt

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

Start Hunting!

Translated by