rearranging a matrix and changing it dimensions

조회 수: 1 (최근 30일)
PIRIL
PIRIL 2015년 10월 16일
편집: Mohammad Abouali 2015년 10월 16일
Hello all,
I have a 104x1000 matrix and I want to reaarange it and have 26x4000 instead.
Lets say that I have a matrix A= [1 2 3; 2 4 5; 3 6 7; 4 5 7] and I want to rearrange it by concatenating 2 rows and have a matrix like this instead X=[1 2 3 2 4 5; 3 6 7 4 5 7].
Could anyone help me ?
Thanks..

채택된 답변

Mohammad Abouali
Mohammad Abouali 2015년 10월 16일
편집: Mohammad Abouali 2015년 10월 16일
use reshape() command:
However, MATLAB rearranges using column order. You are interested in the row base. so you need to do some additional transposing like this:
X=reshape(A',4000,26)';
note that there are two transposes. also check that instead of 26x4000 in the reshape command we are using 4000x26 (due to transpose the final result, i.e. X, would be of size 26x4000). Here is the full code for you example:
A= [1 2 3; 2 4 5; 3 6 7; 4 5 7]
A =
1 2 3
2 4 5
3 6 7
4 5 7
X=reshape(A',[],2)'
X =
1 2 3 2 4 5
3 6 7 4 5 7

추가 답변 (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