GUIDE: gcf windowscrollWheelFcn and gca ButtonDownFcn interaction
8 次查看(过去 30 天)
显示 更早的评论
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?
0 个评论
采纳的回答
Robert Cumming
2014-7-30
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 个评论
Robert Cumming
2014-7-30
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)
更多回答(0 个)
另请参阅
类别
在 Help Center 和 File Exchange 中查找有关 Graphics Object Identification 的更多信息
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!