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!