rearranging a matrix and changing it dimensions

3 views (last 30 days)
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..

Accepted Answer

Mohammad Abouali
Mohammad Abouali on 16 Oct 2015
Edited: Mohammad Abouali on 16 Oct 2015
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

More Answers (0)

Categories

Find more on Creating and Concatenating Matrices in Help Center and File Exchange

Community Treasure Hunt

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

Start Hunting!