Rearranging values in a matrix

1 次查看(过去 30 天)
Gregory Olive
Gregory Olive 2018-3-11
I have a matrix that has 4 columns and I would like to rearrange it to have 5 columns so that the value in the second row first column becomes the value in the first row fifth column. So if the matrix was:
[1 2 3 4
5 1 2 3
4 5 1 2
3 4 5 1
2 3 4 5]
It would become:
[1 2 3 4 5
1 2 3 4 5
1 2 3 4 5
1 2 3 4 5]
Does anybody know how I could do this? Thanks in advance!

回答(1 个)

Von Duesenberg
Von Duesenberg 2018-3-11
Suppose your initial matrix is called oldMat:
reshape(oldMat', [5, 4])'

类别

Help CenterFile Exchange 中查找有关 Resizing and Reshaping Matrices 的更多信息

Community Treasure Hunt

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

Start Hunting!

Translated by