0

我正在尝试使用 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
4

1 回答 1

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
于 2013-01-08T12:35:40.920 回答