So I have found many questions and answers about this on SO
already and I think my approach should work as it is not very complicated. However I have tried every position for my time dimension possible and for me right now reshaping and keeping one dimension the same does not work:
I have a 400x400x20x24 array in which 400x400 is an image and 24 is a number of images at 20 times. I have to do an operation on each voxel and to make this quicker I want to reshape my array into a 2D matrix where one dimension is 20 and only has the time values. I know (or thought I knew) how to do this and have tried every possible order of dimensions prior to reshaping, but none result in my old data:
array1 = rand(400,400,20,24);
This is how one voxel ove time looks
plot([1:20], squeeze(array1(200,200,:,12)))
twoD1 = reshape(array1, [], 20);
size(twoD)
ans = 3840000 20
so far so good until I plot a pixel and its time values
plot([1:20], squeeze(twoD1(962400,:)))
Hmmm wait a minute the dimension of size 20 is no longer the original dimension of size 20, maybe rearranging my original dimensions will affect this.
array2 = permute(array1, [3 1 2 4]);
array3 = permute(array1, [1 3 2 4]);
array4 = permute(array1, [1 2 4 3]);
twoD2 = reshape(array2, [], 20);
twoD3 = reshape(array3, [], 20);
twoD4 = reshape(array4, [], 20);
plot([1:20], squeeze(twoD2(962400,:)))
plot([1:20], squeeze(twoD3(962400,:)))
plot([1:20], squeeze(twoD4(962400,:)))
I dont understand why it doesnt work. Ive looked at these questions, but they seem to suggest I do it right, right?
How do I resize a matrix in MATLAB?
Reshaping a 3 dimensional array to 2 dimensions
Change a multidimensional vector to two dimensional vector matlab
MATLAB reshape matrix converting indices to row index
How to reshape matlab matrices for this example?
Reshape matrix from 3d to 2d keeping rows
Reshape 3d matrix to 2d matrix
Of course I also read:
http://www.mathworks.nl/help/matlab/ref/reshape.html
http://www.mathworks.nl/help/matlab/ref/permute.html
All to no avail. Someone please help me? Thank you!
rand
in your example. – Bas Swinckels