function mousePosition()
hFig = uifigure('Position', [200, 200, 200, 350]);
hText = uilabel(hFig, 'Position', [0, 150, 200, 50], ...
'FontSize', 15, 'BackgroundColor', 'w', ...
'HorizontalAlignment', 'center');
hFig.WindowButtonMotionFcn = ...
@(src, event)moveFcn(hFig, hText);
end

function moveFcn(hFig, hText)
mousePos = get(hFig, 'CurrentPoint');
hText.Text = ...
sprintf('x:%3.0f | y:%3.0f', mousePos);
end