GUIDE: gcf windowscrollWheelFcn and gca ButtonDownFcn interaction

8 Ansichten (letzte 30 Tage)
Hello, thanks for reading this,
I have a problem at the moment with a interaction of axes ButtonDownFcn and the gcf's windowscrollWheelFcn.
I made a simple gui in GUIDE with two axes, and when I ButtonDownFcn on either axes I can print unique messages. Additionally, when I click on a axes and use the windowscrollWheelFcn, I can perform a callback on the axes (I replot rand). However, when I do the windowscrollWheelFcn the callback to ButtonDownFcn no longer works: I can't reprint the message.
Any ideas? When I reprint, I set the HitTest of the image (not the axes) to off when I replot, but it doesn't help the problem. The windowscrollWheelFcn, however, works just fine, which makes me think its a HitTest issue somewhere that's not being set.
EDIT: I just put the additional command behind the windowscrollWheelFcn:
set(gca,'ButtonDownFcn', @axes1_ButtonDownFcn);
and I was able to use the ButtonDownFcn callback again, but only for one of the unique messages (the ButtonDownFcn I point to out of two possible ButtonDownFcn). Is there a way to preserve the original function passing for ButtonDownFcn when I create the axes?

Akzeptierte Antwort

Robert Cumming
Robert Cumming am 30 Jul. 2014
without seeing the actual code I can only speculate - but it sounds like the ButtonDownFcn is being removed when you replot, this happens by design when the axes nextplot property is 'replace'.
See the example below on how changing the nextplot to be 'add' alters the behaviour (note you need to clear the axes "cla" when you want to draw a new plot.
function test
f = figure;
a1 = axes ( 'parent', f, 'position', [0 0 0.5 0.5], 'ButtonDownFcn', @redrawA1 );
a2 = axes ( 'parent', f, 'position', [0.5 0.5 0.5 0.5], 'ButtonDownFcn', @redrawA2, 'nextplot', 'add' );
end
function redrawA1 ( obj, event )
disp( 'in callback A1' );
plot ( gca, rand(10), rand(10) );
end
function redrawA2 ( obj, event )
cla ( gca )
disp( 'in callback A2' );
plot ( gca, rand(10), rand(10) );
end
  3 Kommentare
Robert Cumming
Robert Cumming am 30 Jul. 2014
Change the nextplot property of you axes. Thats what I was demonstrating.
When you re-issue a plot command your callback is being removed (i.e. in your scroll callback you have a plot command -> deleted buttondownfcn callback to the current axes)
Brian
Brian am 30 Jul. 2014
Oh. Thanks! That made it work perfectly.
What I did was change my CreateFcn to include:
function axes1_CreateFcn(hObject, eventdata, handles)
h = plot(rand(10), 'HitTest', 'Off');
set(gcf,'windowscrollWheelFcn', {@scrolldatwheel, gca}, 'nextplot', 'add');
set(gca,'ButtonDownFcn', @axes1_ButtonDownFcn, 'nextplot', 'add');
And it worked. Thank you very much, this was a persisting problem in my GUI.

Melden Sie sich an, um zu kommentieren.

Weitere Antworten (0)

Kategorien

Mehr zu Graphics Object Identification 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