フィルターのクリア

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 Center および File ExchangeAnnotations についてさらに検索

タグ

Community Treasure Hunt

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

Start Hunting!

Translated by