CONNECT TWO gui.FIG IN GUI matlab
显示 更早的评论
Hello,
I'am working in gui Matlab. I created two gui.fig. One is used for the data Input, start and Reset button. The other is used to dispaly the result of simulation. I would like to reset the axes of results in the second gui.fig from the button reset in the first gui.fig.
I try this line of code in the callback of th push button reset but i dosen't work.
% handles2 = getappdata(GUI2);
%cla(handles2,handles.axes_GUI2,'reset');
Any help please
回答(1 个)
Voss
2022-7-8
Here is a working example, where clicking the pushbutton in the first figure clears the axes in the second figure.
The figures, uicontrol, and axes are created programmatically here, as opposed to in GUIDE (which looks like what you are doing). Nevertheless, you can run this example, see how it works, and try to apply the same logic to your code. If you get stuck, share your complete code (and .fig files if using GUIDE).
% first figure, with a pushbutton
handles1.GUI = figure();
handles1.pushbutton = uicontrol(handles1.GUI,'String','Reset','Callback',@reset_axes);
% second figure, with an axes
handles2.GUI = figure();
handles2.axes = axes();
% plot something in the axes so you can see when it resets
plot(handles2.axes,1:10);
% store the handle of the second figure in handles1,
% so that it can be accessed in the pushbutton Callback
handles1.GUI2 = handles2.GUI;
% store each handles structure in its figure
guidata(handles1.GUI,handles1);
guidata(handles2.GUI,handles2);
% pushbutton Callback
function reset_axes(src,evt)
% get the handles structure of the first figure,
% which contains the pushbutton (src)
handles1 = guidata(src);
% get the handles structure of the second figure,
% which contains the axes
handles2 = guidata(handles1.GUI2);
% clear the axes in the second figure
cla(handles2.axes,'reset');
end
类别
在 帮助中心 和 File Exchange 中查找有关 Creating, Deleting, and Querying Graphics Objects 的更多信息
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!