reshape, like pretty much all MATLAB operations, works columnwise. So you just need to transpose, reshape, transpose: X = [20031119 1 2 3 4 5 6 7 8 9;
10 11 12 13 14 15 16 17 18 19;
20 21 22 23 24 25 26 27 28 29;
30 31 NaN NaN NaN NaN NaN NaN NaN NaN;
20031120 1 2 3 4 5 6 7 8 9;
10 11 12 13 14 15 16 17 18 19;
20 21 22 23 24 25 26 27 28 29;
30 31 NaN NaN NaN NaN NaN NaN NaN NaN];
out = reshape(X.',[],size(X,1)/4).';
creates this output matrix:
>> out
out =
Columns 1 through 9:
20031119 1 2 3 4 5 6 7 8
20031120 1 2 3 4 5 6 7 8
Columns 10 through 18:
9 10 11 12 13 14 15 16 17
9 10 11 12 13 14 15 16 17
Columns 19 through 27:
18 19 20 21 22 23 24 25 26
18 19 20 21 22 23 24 25 26
Columns 28 through 36:
27 28 29 30 31 NaN NaN NaN NaN
27 28 29 30 31 NaN NaN NaN NaN
Columns 37 through 40:
NaN NaN NaN NaN
NaN NaN NaN NaN
Best Answer