How to set title for matlab.gra​phics.prim​itive.Imag​e ?

조회 수: 43 (최근 30일)
Wi Iy
Wi Iy 2019년 12월 1일
답변: Steven Lord 2019년 12월 1일
How do I set title for `matlab.graphics.primitive.Image`?
K>>h =
Image with properties:
CData: [1024×1530 double]
CDataMapping: 'scaled'
Show all properties
h =
Image with properties:
CData: [1024×1530 double]
CDataMapping: 'scaled'
Show all properties
AlphaData: 1
AlphaDataMapping: 'none'
BeingDeleted: 'off'
BusyAction: 'cancel'
ButtonDownFcn: ''
CData: [1024×1530 double]
CDataMapping: 'scaled'
Children: [0×0 GraphicsPlaceholder]
Clipping: 'on'
CreateFcn: ''
DeleteFcn: ''
HandleVisibility: 'on'
HitTest: 'on'
Interruptible: 'off'
Parent: [1×1 Axes]
PickableParts: 'visible'
Selected: 'off'
SelectionHighlight: 'on'
Tag: ''
Type: 'image'
UIContextMenu: [0×0 GraphicsPlaceholder]
UserData: []
Visible: 'on'
XData: [1 1530]
YData: [1 1024]
K>> gca
ans =
Axes (Why no name) with properties:
XLim: [0.5000 1.5305e+03]
YLim: [0.5000 1.0245e+03]
XScale: 'linear'
YScale: 'linear'
GridLineStyle: '-'
Position: [0 0 1.0000 1]
Units: 'normalized'
Show all properties
K>> set(gca, 'String', 'Why no title')
Error using matlab.graphics.axis.Axes/set
There is no String property on the Axes class.

채택된 답변

Wi Iy
Wi Iy 2019년 12월 1일
편집: Wi Iy 2019년 12월 1일
I solved it. It turns out that I create the figure with
h = imshow(newImg, 'Border', 'tight');
Trying to set the title won't work, so I need to remove the `Border` option.

추가 답변 (1개)

Steven Lord
Steven Lord 2019년 12월 1일
image objects don't have either a String or a Title property. The axes in which image objects are contained don't have a String property either, but you can give them a title using the title function.
To ensure you're adding the title on the correct axes use ancestor on the image handle.
h = image(magic(16));
ax = ancestor(h, 'axes');
title(ax, 'title for magic image')

카테고리

Help CenterFile Exchange에서 Graphics Object Programming에 대해 자세히 알아보기

태그

Community Treasure Hunt

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

Start Hunting!

Translated by