ButttonDownFcn for axes

ButttonDownFcn for axes

Post by Vince Peta » Thu, 29 Jan 2009 01:30:20


For some reason, I cannot get my ButtonDownFcn to do anything! I've tried a few methods for setting it, but none have yielded any results. I don't get any errors, but simply nothing happens.

First, I tried making a function in my GUI's .m file, and pointing the ButtonDownFcn to it. It uses the axesnumber variable to determine which of three axes is the curernt axes, and the displays structure to determine whether data has been plotted on that axis yet. If so, it runs a function that updates the string in a text box. Here it is:

function axes_click(hObject, eventdata, handles)
global displays axesnumber
pos=get(gcf,'CurrentPoint');
axpos = get(hObject,'Position');
if (pos(1) > axpos(1) && pos(1) < axpos(3)+axpos(1) ...
&& pos(2) > axpos(2) && pos(2) < axpos(4)+axpos(2));
if axesnumber == 1
if displays.one.FileSwitch == 1;
updatenumeric(handles,displays,1);
end
elseif axesnumber == 2
if displays.two.FileSwitch == 1;
updatenumeric(handles,displays,2);
end
elseif axesnumber == 3
if displays.three.FileSwitch == 1;
updatenumeric(handles,displays,3);
end
end
end

set(handles.axes,'ButtonDownFcn',{@axes_click,handles});

When I clicked on an axis... nothing happened.

Then, I tried this:

set(handles.axes,'ButtonDownFcn',...
['global displays handlestwo axesnumber;' ...
'pos=get(gcf,''CurrentPoint'');'...
'axpos = get(hObject,''Position'');' ...
'if (pos(1) > axpos(1) & pos(1) < axpos(3)+axpos(1)' ...
'& pos(2) > axpos(2) & pos(2) < axpos(4)+axpos(2));' ...
'if axesnumber == 1;if displays.one.FileSwitch == 1;' ...
'updatenumeric(handlestwo,displays,1);end;' ...
'elseif axesnumber == 2;if displays.two.FileSwitch == 1;' ...
'updatenumeric(handlestwo,displays,1);end;' ...
'elseif axesnumber == 3;if displays.three.FileSwitch == 1;' ...
'updatenumeric(handlestwo,displays,1);end;end;end;']);

I manually set the ButtonDownFcn to a string-version of the function from before.

Still nothing. I'm really not sure what's going on, and why I can't get this to work. Any ideas?
 
 
 

ButttonDownFcn for axes

Post by Vince Peta » Thu, 29 Jan 2009 01:44:01

> set(handles.axes,'ButtonDownFcn',...

Sorry, there should be:
global handlestwo
handlestwo = handles

above that last one.