MATLAB: Center text on screen

center

Very basic question, but how can I (exactly) center text on screen (or figure window)?
If I just use
text(.5,.5,'x'); axis off
the x is not centered on screen.

Best Answer

% put a small x in the center of a new figure
figure('menubar','none') ;
ah = gca ;
th = text(1,1,'X') ;
set(ah,'visible','off','xlim',[0 2],'ylim',[0 2],'Position',[0 0 1 1]) ;
set(th,'visible','on','HorizontalAlignment','center','VerticalAlignment','middle')