MATLAB: Creating a matrix array for training images. Whats going on

for loopmatrix arrayvoxels

Can someone please explain what is going on in the second loop and how its happening.
N = 90
for i=1:N
% importing files
FName=sprintf('%d.bmp',i);
image1=imread([FFolder1, FName]);
image2=imread([FFolder2, FName]);
image3=imread([FFolder3, FName]);
% taking the 2D image (image1-3) and sticks it into the i'th
% slice (plane) of a 3D image
im1(:,:,i)=image1; % "0"
im2(:,:,i)=image2; % "1"
im3(:,:,i)=image3; % "2"
end
% What is going on in this loop?
for i=1:N
im(:,:,i)=im1(:,:,i);
im(:,:,i+N)=im2(:,:,i);
im(:,:,i+2*N)=im3(:,:,i);
end

Best Answer

Basically you have 3 volumetric images: im1, im2, and im3. That code stacks them on top of each other to form a new volumetric image that is equal to the height of all 3 summed together (because they're stacked in the Z direction).