필터 지우기
필터 지우기

Center text on screen

조회 수: 93 (최근 30일)
Tobias Johansson
Tobias Johansson 2019년 2월 18일
댓글: Tobias Johansson 2019년 2월 18일
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.
  댓글 수: 1
Rik
Rik 2019년 2월 18일
This is actually much more tricky than you might think, since it is not possible to have the anker point of a text object in another place than the lower left corner.
If I recall correctly, there is a submission on the FEX that can be used to create non-overlapping annotations. You can probably use the tricks it uses there to find the length of the text itself (which might be different from the length of the text object itself).

댓글을 달려면 로그인하십시오.

채택된 답변

Jos (10584)
Jos (10584) 2019년 2월 18일
% 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')
  댓글 수: 1
Tobias Johansson
Tobias Johansson 2019년 2월 18일
Thanks, seems to work fine.

댓글을 달려면 로그인하십시오.

추가 답변 (0개)

카테고리

Help CenterFile Exchange에서 Annotations에 대해 자세히 알아보기

태그

Community Treasure Hunt

Find the treasures in MATLAB Central and discover how the community can help you!

Start Hunting!

Translated by