I have a 99x1 cell array and I would like to convert it into a 33x3 cell array for example.
I would like the first 3 rows of the 99x1 cell array to make up the first row in the 33x3 cell array and then the 3rd through 6th row in the 99x1 cell array to make up the second row in the 33x3 cell array.
I also need the data when being reshaped to go over column by column before it goes down. For example I would need:
1 2 3 4
to become
1, 2; 3, 4
not
1, 3; 2, 4
Help with this would be greatly appreciated
You can simply use the reshape
-function. Since reshape(yourcell,[],3)
would first fill the first column and then the second and so on instead of row-wise, you will need to combine it with the transpose operator .'
:
newcell=reshape(yourcell,3,[]).'
This way, you will first create a 3x33
cell using the reshape
and then transform it into the desired 33x3
cell. The []
tells reshape to create as many columns as needed.