The code you have assumes that the file contains a multiframe image with at least 100 frames. If the file has less frames the code will error and if it has more, it will miss these extra frames. It would be much better to use the actual number of frames instead of hardcoding a constant:
img(:, :, :, i) is a 3D matrix, representing the RGB values of frame i, where img(:, :, 1,i) is the red channel, img(:, :, 2, i) is the green channel and img(:, :, 3, i) the blue channel. In effect your code copies all the red channels into a new 3D matrix and discard the green and blue channels. Possibly the code expects the images to be grayscale so all 3 channels should be equal.
The loop is completely unnecessary, the same can be achieve simply with:
img = dicomread('example.dcm')
data = squeeze(img(:, :, 1, :));