Function 使用GUI外函数更新GUI(MATLAB)
我正在尝试使用GUI之外的函数。这是一个.m文件,我想更新GUI组件handles.axes6和handles.axes7。以下是GUI m文件中的脚本Function 使用GUI外函数更新GUI(MATLAB),function,matlab,user-interface,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外部) 函数(单击) 全球rdata; nargin在GUI打开函数中,导出GUI句
function pushbutton8_Callback(hObject, eventdata, handles)
h1 = handles.axes6;
h2 = handles.axes7;
mousemotion(h1,h2);
功能代码(GUI外部)
函数(单击)
全球rdata;
nargin在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
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
然后在任何函数func1中,按如下方式使用它们:
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
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
你还有问题吗?非常感谢你的帮助。但是如果我想链接这两个句柄并用它们代替gcf呢?有可能吗?我想同时设置两者。我不太了解您,但使用setappdata([handle]、“[any data name]、[any data value])代码>,以及[variable]=getappdata([handle],“[any data name]”)
要设置和获取信息,您可以为任何句柄设置信息,将应用程序数据作为信息存储库处理。我的两个句柄(handles.axes6和handles.axes7)用于两个3d轴。我需要一起旋转这两个轴。所以我想在我的外部函数中链接这两个句柄;通过将函数与axes事件链接,该函数不起作用,但是该函数应该在axes上应用一些处理,这非常简单,当您在axes6上执行任何操作时,只需在axes7上再次复制相同的代码即可