rearranging a matrix and changing it dimensions

3 Ansichten (letzte 30 Tage)
PIRIL
PIRIL am 16 Okt. 2015
Bearbeitet: Mohammad Abouali am 16 Okt. 2015
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..

Akzeptierte Antwort

Mohammad Abouali
Mohammad Abouali am 16 Okt. 2015
Bearbeitet: Mohammad Abouali am 16 Okt. 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

Weitere Antworten (0)

Kategorien

Mehr zu Creating and Concatenating Matrices finden Sie in Help Center und File Exchange

Community Treasure Hunt

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

Start Hunting!

Translated by