Input image size in MATLAB
It's not a MATLAB'ish way of doing that, try:

[xmax, ymax, nchan] = size(read);


Where nchan is the number of channels. Also it can be done by:

xmax = size(read, 1);
ymax = size(read, 2);


Or even:

[xmax, ymax, ~] = size(read);