Q:

Partition Image into 9 equal or nearly equal partitions: Matlab

I need to partition an image to 9 equal or nearly equal partitions and store each of the partition into an array. So, the end result would be like array of arrays where each element of an array is a 2x2 array representing a partition of image. So far, I have come up with the following code
function [ outputImageRectangles ] = getImagePartitions( inputImage )
%Write the code to partition image into 9 equal or nearly equal size
%rectangles
[height, width] = size(inputImage);
partitions = zeros(3,3);
for i=0:2
    for j=0:2
        loweri = floor(i*height/3)+1;
        higheri = floor((i+1)*height/3);
        lowerj = floor(j*width/3)+1;
        higherj = floor((j+1)*width/3);
        x = i+1;
        y = j+1;
        loweri
        higheri
        lowerj
        higherj

        partitions(x,y,:,:) = inputImage(loweri:higheri, lowerj:higherj);
    end
end
outputImageRectangles = partitions;

end

I assume that process of partitioning works fine but i have problems storing each partition into an array element. I am very new to matlab and just trying to get a grip on it. I also read a bit about cell arrays which can contain another array as an array element. So far, this code gives me errors on 
 partitions(x,y,:,:) = inputImage(loweri:higheri, lowerj:higherj);

obviously because there are array dimensions mismatch. My question is how to perform this task without degrading the performance too much? Performance is critical because this function will be called for more than 12000 images.  

A:

Just use a cell array. As your subblocks are not the same size, its the best option to store the data.
partitions{x,y} = inputImage(loweri:higheri, lowerj:higherj);

