gco function not working (as expected)

14 Ansichten (letzte 30 Tage)
Jeff Wood
Jeff Wood am 8 Jun. 2016
Kommentiert: Jeff Wood am 9 Jun. 2016
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?

Antworten (1)

Walter Roberson
Walter Roberson am 8 Jun. 2016
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
  1 Kommentar
Jeff Wood
Jeff Wood am 9 Jun. 2016
As I mentioned it was a simplified listing (which I left out the pause.
The complete listing is at https://raw.githubusercontent.com/WoodMath/thesis_matlab/master/StereoPoints/fnMenuDelete.m
Anyway it doesn't seem to be an issue anymore.

Melden Sie sich an, um zu kommentieren.

Kategorien

Mehr zu Creating, Deleting, and Querying Graphics Objects finden Sie in Help Center und File Exchange

Community Treasure Hunt

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

Start Hunting!

Translated by