使用GUI(MATLAB)中的函数更新GUI

时间:2013-01-08 07:27:25

标签: function matlab user-interface

我正在尝试使用GUI之外的功能。它是一个.m文件,我想更新GUI组件,即handles.axes6和handles.axes7。以下是GUI m文件中的脚本。

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

1 个答案:

答案 0 :(得分:0)

在GUI Opening功能中,导出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