How to share data between two GUI ?
1 visualización (últimos 30 días)
Mostrar comentarios más antiguos
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 comentarios
Jan
el 1 de Jul. de 2018
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.
Respuestas (1)
Jan
el 1 de Jul. de 2018
Editada: Jan
el 1 de Jul. de 2018
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
Ver también
Categorías
Más información sobre Whos en Help Center y File Exchange.
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!