The difference between the first and second blocks of code in your question is that in block 2 you are specifying x and y values in the image whereas in block 1, imagesc is creating the x and y values. When imagesc creates the x and y values, they are integer indices which makes indexing within the localDcmFcn straightforward. When you specify the x and y values, the XData and YData in the image are no longer integers that correspond with the indices of CData so they can't be used as indices.
To illustrate this point, consider this line and look at the event.Position values produced by both block 1 and block 2 in your question. In block 1, those values will be integers that can be indexed into CData. In block 2, those values are floating point decimals that cannot be used as indices.
idx = event.Target.CData(event.Position(2),event.Position(1));