function mousePosition
hText = uicontrol('Units', 'normalized', ...
   'Position', [0.3 0.475 0.4 0.05] , ...
   'Style', 'text', ...
   'BackgroundColor', 'w', ...
   'FontSize', 15);
set(gcf, 'WindowButtonMotionFcn', ...
   @(hFig, event)moveFcn(hFig, hText));
end

function moveFcn(hFig, hText)
% WindowButtonMotionFcn of figure
mousePos = get(hFig, 'CurrentPoint');
set(hText, 'String', ...
   sprintf('x:%3.0f | y:%3.0f', mousePos));
end
