https://in.mathworks.com/help/images/ref/randomcropwindow3d.html
randomCropWindow3d - Create randomized cuboidal cropping window - MATLAB
This MATLAB function determines the window to crop from a 3-D input image of size inputSize such that the size of the cropped image is targetSize.
createrandomizedcroppingwindowmatlab