フィルターのクリア

Why after plotting on axes the ButtonDownFcn doesn't work?

25 ビュー (過去 30 日間)
Dani Tormo
Dani Tormo 2012 年 11 月 29 日
コメント済み: David Willis 2017 年 8 月 4 日
Hi,
I have a GUI with 3 axes. Before plotting the data the three functions axesX_ButtonDownFcn(...) work, but when I plot the data they don't work anymore.
I have tried this but doesn't work:
axes(handles.plot1);
handles.cursorPlot1 = plot(handles.simulation_data_temp(8,:), 'Parent',...
handles.axes1, 'HitTest', 'off', 'ButtonDownFcn', '');
What I am doing wrong?
Thanks.
  2 件のコメント
Bing
Bing 2017 年 4 月 16 日
You should do this:
% code
set(handles.plot1,'NextPlot','new');
cla(handles.plot1);
axes(handles.plot1);
handles.cursorPlot1 = plot(handles.simulation_data_temp(8,:), 'Parent',...
handles.axes1, 'HitTest', 'off');
David Willis
David Willis 2017 年 8 月 4 日
For simple folks like me, all you need is this. I created a button and an axes. When I press the button it plots a sinewave on the axes. When I click in the axes window, the coordinates are displayed.
function pushbutton1_Callback(hObject, eventdata, handles)
%pushbutton callback function
x = 0:100;
y = sin(2*pi*x/20);
set(handles.axes1, 'nextPlot','new'); %this is the key!
axes(handles.axes1);
plot(x,y);
% ButtonDown callback for axes1
function axes1_ButtonDownFcn(hObject, eventdata, handles)
coord = get(hObject, 'CurrentPoint') %No semicolon so it is displayed
pts = coord(1,1:2)

サインインしてコメントする。

採用された回答

Matt Fig
Matt Fig 2012 年 11 月 29 日
編集済み: Matt Fig 2012 年 11 月 29 日
>> AxesH = axes('ButtonDownFcn', 'disp(''Axes click!'')');
Axes click!
Axes click!
>> plot(1:10) % Now clicking does nothing....
No more 'Axes click!', but now try this:
>> clear all,close all
>> AxesH = axes('ButtonDownFcn', 'disp(''Axes click!'')');
Axes click!
>> hold all
>> plot(1:10)
Axes click!
Axes click!
Basically, when you plot on an axes that has the nextplot property set to replace, all callbacks, etc are reset in that call.
  2 件のコメント
Dani Tormo
Dani Tormo 2012 年 11 月 29 日
hold all
That works!
So, to continue with Jan Simon's example, and differenciating both clicks on axes and on the line, this is how it will work:
AxesH = axes('ButtonDownFcn', 'disp(''Axes click!'')');
hold all
Plot1 = plot(1:10, 'hittest', 'on', 'buttondownfcn', 'disp(''Line click!'')');
Thank you all guys!!
Jan
Jan 2012 年 11 月 29 日
Fine, Matt! I've seen this for image(), but did not assume that this happens for plot() also. But why did I not see this in my test code?? For testing of a foreign toolbox I've added this in matlabrc.m:
set(0, 'DefaultAxesNextPlot', 'add')
Afterwards I cleanup startup.m. This worked for month now, because in my own programs I use the faster low-level functions like line().

サインインしてコメントする。

その他の回答 (3 件)

Deep Desai
Deep Desai 2014 年 6 月 25 日
編集済み: Deep Desai 2014 年 6 月 25 日
Jan, would I be expected to do the same incase I was using a function and not displaying a text.
My code;
set(handles.threat,'HitTest','off');
set(handles.threat, 'ButtonDownFcn', {@threat_ButtonDownFcn,handles});
hold all
scatter(handles.threat,green_distance, gGreenTime,'g*');
function threat_ButtonDownFcn(hObject, eventdata, handles)
P = get(handles.threat,'CurrentPoint');
Thanks again mate.

Jan
Jan 2012 年 11 月 29 日
編集済み: Jan 2012 年 11 月 29 日
You set the ButtonDownFcn explicitly to the empty string. What kind of processing do you expect afterwards?
[EDITED]
AxesH = axes('ButtonDownFcn', 'disp(''Axes click!'')');
Plot1 = plot(1:10, 'Parent', AxesH, 'HitTest', 'off', 'ButtonDownFcn', '');
Now clicking on the axes still works. Please test this. And now find out, where in your code the ButtonDownFcn is overwritten. And/or set a breakpoint in the ButtonDownFcn to find out, if it is still called, but any other error occurres.
  4 件のコメント
Dani Tormo
Dani Tormo 2012 年 11 月 29 日
Using your example:
AxesH = axes('ButtonDownFcn', 'disp(''Axes click!'')');
ButtonDownFcn works fine. Then I execute the next command:
Plot1 = plot(1:10, 'Parent', AxesH, 'HitTest', 'off', 'ButtonDownFcn', 'disp(''Axes click 2!'')');
Now when you click on the line, matlab shows Axes click 2!
But if I check the field 'ButtonDownFcn' of AxesH it's empty. Do you know why?
Assigning again the 'ButtonDownFcn' to AxesH work both, showing Axes click! when you click on the axes, and Axes click 2! when you click on the line.
But why it is overwrited?
Thanks for your help, man!
Dani Tormo
Dani Tormo 2012 年 11 月 29 日
Thanks Jan, hold all solves this problem.

サインインしてコメントする。


Image Analyst
Image Analyst 2012 年 11 月 29 日
  1 件のコメント
Dani Tormo
Dani Tormo 2012 年 11 月 29 日
Thanks!
I tried but it didn't work. After plotting the field ButtonDownFcn of AxesH is empty. Why this happens?
I wrote the explanation on Jan's comment.

サインインしてコメントする。

カテゴリ

Help Center および File ExchangeAnnotations についてさらに検索

製品

Community Treasure Hunt

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

Start Hunting!

Translated by