MATLAB: How to split a double array in left and right sides

3d imagecount voxelsfmrisplit along axissplit arrayspm

Dear experts,
I have a 3d array with dim 51x75x55 double and I want to calculate the N elements above a certain threshold (>2.3). However, I want to compare N elements above threshold in the left side of the original image with N elements above threshold in the right side of the image. How do I split a 3d array into a left and right side, according to the original image, which is a map of brain activation patterns?
I am still a kind of noob when it comes to matlab, so I appreciate simple explanations. 🙂 p.s.: I don't have any matlab toolboxes available, so I can't use functions from e.g. the image processing toolbox.
Thank you in advance!

Best Answer

You can do this with just matrix indexing. To get the left half of a matrix, you can index it with the expression "1:floor(end/2)". As you can see, this indexes from the first element to the middle element (located halfway to the end of the matrix). The "floor" function rounds down, which is necessary if the matrix has an odd number of elements, since you can't select half an element. For the right half, it would be a similar expression, "ceil(end/2):end". In this case, we index from the middle element (rounded up) to the end of the matrix. In the case of a 3D matrix where you want to split by column, your code would look similar to the following:
Left = MyImage(:, 1:floor(end/2), :);
Right = MyImage(:, ceil(end/2):end, :);
Related Question