Retrieve Imline handle from axes

1 次查看(过去 30 天)
Hi,
having trouble retrieving handle to Imline objects created within an axes. It is running in a multi-step GUI and I am trying to update the Imline position when a user inputs a selection of x and y values.
Issue can be reproduced using below:
fh = figure;
ah = axes(fh);
imshow('pout.tif');
h = imline(ah,[10 100], [100 100]);
clear all % you must put this in as I’m running from the gui
H=get(gca,'Children')
H =
2x1 graphics array:
Group (imline)
Image
setPosition(H(1),[50 200], [140 200])
ERROR: Undefined function 'setPosition' for input arguments of type 'matlab.graphics.primitive.Group'.
Any help would be most appreciated

采纳的回答

Walter Roberson
Walter Roberson 2016-6-30
I confirm that in R2016a. I do not know why it happens. The workaround is
setPosition(H(1).ApplicationData.roiObjectReference,[50 200],[140 200])

更多回答(1 个)

Geoff Hayes
Geoff Hayes 2016-6-30
Matt - which version of MATLAB are you using? If you are using an older version of MATLAB, you may not have the ability to call the setPosition method and instead will have to update the position property. What properties are returned when you execute the following
get(H(1))
Is there a Position such that you could do
set(H(1), 'Position', 50 200], [140 200]);
Also, why do you "lose" the handle h after you initially create this object? Why the clear all statement?
  1 个评论
Matt_Z
Matt_Z 2016-6-30
Hi Geoff and thanks for getting back to me.
the reason the handle is lost is it is embedded into a callback routine of a GUI. I have tried to save the handle to the figure using setappdata but this returns the same handle structure as H=get(gca,'Children')
To answer your question I am using R2016a and get(H(1)) returns:
Annotation: [1x1 matlab.graphics.eventdata.Annotation]
BeingDeleted: 'off'
BusyAction: 'queue'
ButtonDownFcn: ''
Children: [4x1 Line]
CreateFcn: ''
DeleteFcn: @imlineAPI/deleteContextMenu
DisplayName: ''
HandleVisibility: 'on'
HitTest: 'on'
Interruptible: 'on'
Parent: [1x1 Axes]
PickableParts: 'visible'
Selected: 'off'
SelectionHighlight: 'on'
Tag: 'imline'
Type: 'hggroup'
UIContextMenu: [0x0 GraphicsPlaceholder]
UserData: []
Visible: 'on'
Unfortunately set(H(1), 'Position', [50 200], [140 200]) does not work and provides the following:
Error using matlab.graphics.primitive.Group/set Invalid parameter/value pair arguments.

请先登录,再进行评论。

类别

Help CenterFile Exchange 中查找有关 Interactive Control and Callbacks 的更多信息

标签

Community Treasure Hunt

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

Start Hunting!

Translated by