MATLAB: GUI ButtonDownFcn for clicking on axes

axesdouble clickguiMATLAB

Hi all, I've got 2 axes in my GUI, and I want to be able to launch a different .m file when the user clicks either axes.
Currently I can launch a function, but I'm unable to differentiate between the different axes, and I'd rather directly run a .m script if possible.
I currently have:
h(1)=imshow(thumb_1, [])
h(2)=imshow(thumb_2, [])
function load_stuff(hObject, eventdata, handles) X=100;
Also using the code above, I seem to be unable to access the handles structure in my "load_stuff" function!
Can anyone help my plight?
Thanks, Jim

Best Answer

I would use the 'ButtonDownFcn' property on each axes, and make the callback function be a call to the run function which will execute your script.
So let's say you have to scripts named s1.m and s2.m. Assuming they're both on the MATLAB path, you can do this:
a1 = axes('Position', [0.1 0.1 0.4 0.4], 'ButtonDownFcn', @(s,e) run('s1'));
a2 = axes('Position', [0.5 0.5 0.4 0.4], 'ButtonDownFcn', @(s,e) run('s2'));
(I'm setting the position property there just so you can see both of the axes in the same figure.)
If the scripts s1.m and s2.m are not on the path, then you can specify the full path to them in the call to run.