Matrix Elements Re-ordering

조회 수: 3 (최근 30일)
Pedro Oliveira
Pedro Oliveira 2017년 10월 24일
댓글: Cedric 2017년 10월 24일
If I have a matrix A that is:
A = [1, 2; 3, 4; 5, 6;7, 8]
How can I reorder it so that it becomes,
A = [1,3;5,7;2,4;6,8]
i.e. basically re.arranging the matrix elements in a row-by-row basis (the first 2 elements of column 1 become the 2 elements in row 1; the second 2 elements of column 1 become the 2 elements in row 2, etc).
Thank you for your help in advance!

채택된 답변

Cedric
Cedric 2017년 10월 24일
>> B = reshape( A, 2, [] ).'
B =
1 3
5 7
2 4
6 8
  댓글 수: 2
Pedro Oliveira
Pedro Oliveira 2017년 10월 24일
Thank you!
Cedric
Cedric 2017년 10월 24일
My pleasure!

댓글을 달려면 로그인하십시오.

추가 답변 (0개)

카테고리

Help CenterFile Exchange에서 Matrices and Arrays에 대해 자세히 알아보기

Community Treasure Hunt

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

Start Hunting!

Translated by