I think you got this error:
Index exceeds the number of array elements
As stated above, you need to use the meshed X and Y.
Digging further into this, the indicies of the output of the imregionalmax function is given in linear array indicies and not 2D (row, columns) as one would normally expect. I had the same problem and another way to solve this is to use the convert linear indices to subscripts function ind2sub
ix = find(imregionalmax(z));
[a,b] = ind2sub(size(z),ix);
I am not sure if it will give you 100% what you are looking for, but explains the previous behaviour and another way on how to fix it.