2013-01-08 87 views
0

我試圖使用GUI之外的函數。它是一個.m文件,我想更新句柄爲handle.axes6和handles.axes7的GUI組件。以下是GUI m文件中的腳本。使用GUI(MATLAB)中的函數更新GUI

function pushbutton8_Callback(hObject, eventdata, handles) 

h1 = handles.axes6; 
h2 = handles.axes7; 

mousemotion(h1,h2); 

功能碼(外GUI)

function mousemotion(click) 
global rdata; 
nargin<1 
    set(gcf,'WindowButtonDownFcn','mousemotion(''down'')'); 
    set(gcf,'WindowButtonUpFcn','mousemotion(''up'')'); 
    set(gcf,'WindowButtonMotionFcn',''); 
    axis vis3d 
+0

你也有問題嗎? – Nick

回答

0

裏面的GUI開啓功能,導出GUI手柄,你軸處理,然後從你所需要的,像下面的功能讓他們:

function figure_OpeningFcn(hObject, eventdata, handles,varargin) 

%// This function has no output args, see OutputFcn. 
%// hObject handle to figure 
%// eventdata reserved - to be defined in a future version of MATLAB 
%// handles structure with handles and user data (see GUIDATA) 
%// varargin command line arguments to DatabaseViewerApp (see VARARGIN) 

%// Choose default command line output for DatabaseViewerApp 
handles.output = hObject; 

%// Update handles structure 
guidata(hObject, handles); 
%// UIWAIT makes DatabaseViewerApp wait for user response (see UIRESUME) 
%// uiwait(handles.mainFigure); 

    %//set the current figure handle to main application data 
    setappdata(0,'figureHandle',gcf); 

    %//set the axes handle to figure's application data 
    setappdata(gcf,'axesHandle1',handles.axes6); 

    %//set the axes handle to figure's application data 
    setappdata(gcf,'axesHandle2',handles.axes7); 

end 

然後在任何功能FUNC1,使用它們如下所示:

function varargout = func1(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'); 

%// And here you can write your own code using your axes 

end 
+0

非常感謝您的幫助。但是如果我想鏈接這兩個句柄並使用它們代替gcf呢?有可能這樣做嗎?我想同時設置兩者。 – user1953847

+0

我不太瞭解你,但是使用'setappdata([handle],'[any-data-name]',[any-data-value]);'和'[variable] = getappdata([handle] ,'[any-data-name]');'設置和獲取信息,你可以爲任何句柄設置信息,處理應用程序數據作爲你的信息庫。 –

+0

我的兩個手柄(handles.axes6和Handles.axes7)適用於兩個3D軸。我需要將這兩個軸旋轉在一起。所以我想在我的外部函數中鏈接這兩個句柄。 – user1953847