This really really really depends on the operation you want to apply. For example, if you want to dilate each image with a 3x3 square, all you have to do is pass the 3D matrix and the 3x3 square.
imdilate (img, true (3, 3));
This simple example will apply dilation on all the 2D images of the matrix, it's all a matter of choosing the right structuring element (the true (3, 3)
). Of course, you can use a for loop too, but that's not how this language was meant to be used. And isn't the example above much more elegant than a loop?
A well designed function for the Matlab language should be handling this cases for you, and work across all images of a n-dimensional matrix. It is up to you to understand the operator and function well enough to make it do what you want.