How to share data between two GUI ?
1 次查看(过去 30 天)
显示 更早的评论
Problem:
1. Two GUI are created with name First.fig / First.m and Second.fig / Second.m.
2. Both GUI have two radio button namely first and second.
3. With one condition : only once GUI can be open at a time.
4. Expected output should be if second radio button is selected in First GUI then it should get reflected in second radio button of Second GUI.
2 个评论
Jan
2018-7-1
This cannot work due to restriction 3. : If you can open one GUI only, you cannot share data between two GUIs.
So please explain the problem more clearly.
回答(1 个)
Jan
2018-7-1
编辑:Jan
2018-7-1
function CreateGUI1
FigH = figure('Tag', 'GUI1', 'Name', 'GUI 1');
handles.Radio(1) = uicontrol('Style', 'Radiobutton', 'String', 'Radio 1', ...
'Position', [10, 10, 100, 30]);
handles.Radio(2) = uicontrol('Style', 'Radiobutton', 'String', 'Radio 2', ...
'Position', [10, 40, 100, 30]);
guidata(FigH, handles);
end
And the 2nd GUI:
function CreateGUI2
FigH = figure('Tag', 'GUI2', 'Name', 'GUI 2');
handles.Radio(1) = uicontrol('Style', 'Radiobutton', 'String', 'Radio 1', ...
'Position', [10, 10, 100, 30], ...
'Callback', {@radio, 1});
handles.Radio(2) = uicontrol('Style', 'Radiobutton', 'String', 'Radio 2', ...
'Position', [10, 40, 100, 30], ...
'Callback', {@radio, 2});
guidata(FigH, handles);
end
function radio(RadioH, EventData, Index)
% Get handle and handles struct of GUI1:
GUI1 = findobj(allchild(groot), 'flat', 'Tag', 'GUI1');
handlesGUI1 = guidata(GUI1H);
handlesGUI2 = guidata(RadioH);
if Index == 1
handlesGUI1.Radio(1).Value = 1; % Copy state to other GUI
handlesGUI1.Radio(2).Value = 0; % Copy state to other GUI
handlesGUI2.Radio(2).Value = 0; % Disable the other radio button
else
handlesGUI1.Radio(2).Value = 1;
handlesGUI1.Radio(1).Value = 0;
handlesGUI2.Radio(1).Value = 0;
end
end
另请参阅
类别
在 Help Center 和 File Exchange 中查找有关 Whos 的更多信息
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!