gco function not working (as expected)
14 次查看(过去 30 天)
显示 更早的评论
I have the following (simplified) code I wrote which is supposed to select n points (of type 'line') on a figure and delete them
for i_inc = 1:n
while(~(strcmpi(get(gco,'type'),'line')))
end %%Loops until a line is selected
h_parent = get(gco, 'Parent'); %%Parent is of type 'Axes'
h_current = get(gco);
gco(h_parent); %%Set handle to parent so gco type is no longer 'line'
delete(h_current);
end
The problem is when I call the GCO function, the gco handle does not change. I can change the GCO manually by clicking on different items in a figure, but this defeats the purpose of what the 'gco' function is supposed to do.
Any suggestions?
0 个评论
回答(1 个)
Walter Roberson
2016-6-8
You are not using pause() or waitfor() or uiwait() or drawnow() in your while loop, so no graphics interrupts will happen in your loop and the callback object will not get updated.
gco(h_parent); %%Set handle to parent so gco type is no longer 'line'
"gco(figure_handle) returns the handle of the current object in the figure specified by figure_handle"
Calling gco and passing in a parameter does not activate the object that you pass in: the parameter just gives you a way to inquire about an object other than the current figure.
"The current object is the last object clicked or selected via keyboard interaction, excluding uimenus."
There is no documented way of giving that "last clicked or selected via keyboard interaction" away. The closest to that is the use of Java Robot to fake a click or keypress for you.
On the other hand, in practice you can set() the figure CurrentObject property and that affects gco
另请参阅
类别
在 Help Center 和 File Exchange 中查找有关 Creating, Deleting, and Querying Graphics Objects 的更多信息
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!