2

I would like to connect my two axes.handles so that when the mouse button is clicked on one, the other one would also do what the first one do. I have an external function that executes out what I want to do when the mouse is clicked. I just need to update the two handles in GUI so that it will do the same thing when one axes is clicked.

In Main GUI

function testminiproj_OpeningFcn(hObject, ~, handles, varargin)
handles.output = hObject;
handles.done=0;
guidata(hObject, handles);

setappdata(0,'figureHandle',gcf);

setappdata(gcf,'axesHandle1',handles.axes6);

setappdata(gcf,'axesHandle2',handles.axes7);

And this is my external function which is callback into main GUI by calling mousemotion;

function varargout = mousemotion(this,varargin)

%// get the figure handle from the application main data
figureHandle = getappdata(0,'figureHandle');

%// get the axes handle from the figure data
axesHandle1 = getappdata(figureHandle,'axesHandle1');

%// get the axes handle from the figure data
axesHandle2 = getappdata(figureHandle,'axesHandle2');

global rdata;
if nargin<1
  set(gcf,'WindowButtonDownFcn','mousemotion(''down'')');
  set(gcf,'WindowButtonUpFcn','mousemotion(''up'')');
  set(gcf,'WindowButtonMotionFcn','');

Appreciate any help. I am bad at trying to put the question across. Hope someone could help. Thanks.

  • You want to write set(axesHandles, ...) instead of set(axesHandle1, ..) and set(axesHandle2, ..). Am I right? – HebeleHododo Jan 09 '13 at 06:42
  • Yes. I want to link this two axeshandles so that when I perform one action on one, the other one will also follow suit. – user1953847 Jan 09 '13 at 07:01

2 Answers2

0

You can make a handles vector. Like this:

axesHandles = [axesHandles1; axesHandles2];
set(axesHandles, 'PropertyName', PropertyValue);

This way both axes' property values will be set to PropertyValue.

HebeleHododo
  • 3,620
  • 1
  • 29
  • 38
  • I get this error when I tried: `Error using hg.axes/set The name 'WindowButtonDownFcn' is not an accessible property for an instance of class 'axes'.` – user1953847 Jan 09 '13 at 07:13
  • @user1953847 That is because 'WindowButtonDownFcn' is a [figure property](http://www.mathworks.com/help/matlab/ref/figure_props.html), not an [axes property](http://www.mathworks.com/help/matlab/ref/axes_props.html). – HebeleHododo Jan 09 '13 at 07:18
  • If its a figure property then how do I go about manipulating it. Because I want to replace gcf with axesHandles. – user1953847 Jan 09 '13 at 07:20
  • Are your axes in the same figure? If so, `set(figureHandle, 'WindowButtonDownFcn', @yourfunction);` should work. – HebeleHododo Jan 09 '13 at 07:23
  • yes they are. But I have 6 axes in a figure.Thanks for your help but it still doesn't work and I don't know why. – user1953847 Jan 09 '13 at 08:29
  • @user1953847 Does that mean you want to link all 6 axes or just the ones the user clicked? – HebeleHododo Jan 16 '13 at 07:28
0

You need to work around and manually find out which axes is clicked in.

It's actually not hard. Just use the Position attribute of the figure and axes.

bdecaf
  • 4,652
  • 23
  • 44
  • It is clicked in handles.axes6. Actually it should not matter which axes is clicked. When one of the either two is clicked then the other one will follow the same action while corresponding to the clicked axes. How do I use that? – user1953847 Jan 09 '13 at 13:15