add a function to be executed for a subplot ButtonDownFcn event

조회 수: 14 (최근 30일)
Varsha
Varsha 2011년 10월 13일
I need to add a function to the ButtonDownFcn event of a subplot which will open another figure.
I am using:
subplot(3,4,1,'ButtonDownFcn',{@mySubplotCallback, arrData});
and
function mySubplotCallback(src,eventdata,x)
figure (100)
pie(x);
end
Where am going wrong here?

답변 (2개)

Fangjun Jiang
Fangjun Jiang 2011년 10월 13일
Nothing is wrong. You just need to move your cursor over the subplot and then press button down. It worked for me as I tried.
subplot(3,4,1,'ButtonDownFcn',{@mySubplotCallback, rand(5,1)})
I see the problem. If the following two lines are executed, it looks like the pie chart blocked the subplot axes such that the button down function callback is not triggered.
subplot(3,4,1,'ButtonDownFcn',{@mySubplotCallback, rand(5,1)});
pie(rand(5,1))
One solution is to do this:
subplot(3,4,1,'ButtonDownFcn',{@mySubplotCallback, rand(5,1)});
p=pie(rand(5,1));
set(p,'ButtonDownFcn',{@mySubplotCallback, rand(5,1)});

Varsha
Varsha 2011년 10월 13일
Yes, it works, now when I add a pie chart on the subplot, it no longer works subplot(3,4,1,'ButtonDownFcn',{@mySubplotCallback, arrData}); pie(arrData);

카테고리

Help CenterFile Exchange에서 Subplots에 대해 자세히 알아보기

Community Treasure Hunt

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

Start Hunting!

Translated by