在 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