Why findobj cannot find a TexBox (annotation) object?

23 ビュー (過去 30 日間)
Kouichi C. Nakamura
Kouichi C. Nakamura 2020 年 12 月 4 日
While HandleVisibility property of a TextBox object is 'on' by default,
fig = figure
txb = annotation('textbox',[0.5 0.5 0.5 0.5],'String','bar hoo')
class(txb)
ans =
'matlab.graphics.shape.TextBox'
txb.Type %
ans = 'textboxshape'
txb.HandleVisibility
ans = 'on'
findobj cannot find this txb.
findobj(fig,'Type','textboxshape')
ans =
0×0 empty GraphicsPlaceholder array.
Why is this and how can I find this txb?

採用された回答

Cris LaPierre
Cris LaPierre 2020 年 12 月 4 日
編集済み: Cris LaPierre 2020 年 12 月 4 日
Try using the object handle (txb) directly.
plot(1:10)
str = 'Straight Line Plot from 1 to 10';
txb = annotation('textbox',[.2 .5 .3 .3],'String',str,'FitBoxToText','on');
% Use object handle
findobj(txb)
ans =
TextBox (Straight Line Plot from 1 to 10) with properties: String: 'Straight Line Plot from 1 to 10' FontName: 'Helvetica' FontSize: 10 FontWeight: 'normal' Color: [0 0 0] BackgroundColor: 'none' EdgeColor: [0 0 0] LineStyle: '-' LineWidth: 0.5000 Position: [0.2000 0.5000 0.3000 0.3000] Units: 'normalized' Show all properties
If you want to instead find the annotation without using the object handle, use findall instead.
findall(gcf,'Type','textboxshape')
ans =
TextBox (Straight Line Plot from 1 to 10) with properties: String: 'Straight Line Plot from 1 to 10' FontName: 'Helvetica' FontSize: 10 FontWeight: 'normal' Color: [0 0 0] BackgroundColor: 'none' EdgeColor: [0 0 0] LineStyle: '-' LineWidth: 0.5000 Position: [0.2000 0.5000 0.3000 0.3000] Units: 'normalized' Show all properties
  4 件のコメント
Cris LaPierre
Cris LaPierre 2020 年 12 月 4 日
Good point. The underlying issue was handle visibility, as you pointed out below. I'll update my response to remove any confusion.
Kouichi C. Nakamura
Kouichi C. Nakamura 2020 年 12 月 4 日
Thanks!

サインインしてコメントする。

その他の回答 (1 件)

Kouichi C. Nakamura
Kouichi C. Nakamura 2020 年 12 月 4 日
It turned out that TextBox txb is a child of an AnnotationPane or 'matlab.graphics.shape.internal.AnnotationPane' object. And HandleVisibility of AnnotationPane objects are 'off' by default, hiding the handle of TextBox txb.
So you need to set HandleVisibility of AnnotationPane objects to 'on' first, and then use findobj.
set(findobj(allchild(fig),'Type','AnnotationPane'),...
'HandleVisibility','on')
findobj(fig,'Type','textboxshape') % WORKS!
ans =
TextBox (bar hoo) with properties:
String: 'bar hoo'
FontName: 'Helvetica'
FontSize: 10
FontWeight: 'normal'
Color: [0 0 0]
BackgroundColor: 'none'
EdgeColor: [0 0 0]
LineStyle: '-'
LineWidth: 0.5000
Position: [0.5000 0.5000 0.5000 0.5000]
Units: 'normalized'

カテゴリ

Help Center および File ExchangeGraphics Object Identification についてさらに検索

Community Treasure Hunt

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

Start Hunting!

Translated by