Gui that opens another gui. Need to send variables from one gui to other gui and vice versa
2 Ansichten (letzte 30 Tage)
Ältere Kommentare anzeigen
Right now I have a Main Gui and a Sub Gui. I need two variables from the main gui to copy to my sub gui, and two variables from my sub gui to copy to my main gui. The Main gui has a button called "calculator' that opens my sub gui. The two guis have separate scripts. I have looked at using guidata and sendappdata but I can't seem to find how to tell matlab the variable is in a different script.
I want to send variable a and variable b from my Main GUI to my Sub gui (when I press pushbutton'Calculator') and then variable c and variable d from my Sub GUI to my Main GUI when I press the pushbutton 'OK' in the sub gui. variables a and b are from listboxes in Main gui. variables c and d are from editText boxes in sub gui.
The Main gui stays open when I open the sub gui.
I am not sure what code to include to help with this question, so if you need to see some of my code please ask and tell me what part would be helpful.
0 Kommentare
Antworten (5)
Matt Fig
am 9 Jun. 2011
Here is an example. Adapt it to your needs...
function [] = gui_passdata()
% Pass data back and forth...
S.fh = figure('units','pixels',...
'position',[500 500 200 130],...
'menubar','none',...
'numbertitle','off',...
'name','gui_passdata',...
'resize','off');
S.ed = uicontrol('style','edit',...
'units','pix',...
'position',[10 60 180 60],...
'string','Enter Data, push button.');
S.pb = uicontrol('style','pushbutton',...
'units','pix',...
'position',[10 20 180 30],...
'string','Push to Get Data',...
'callback',{@pb_call,S});
guidata(S.fh,S);
uicontrol(S.ed)
function [] = pb_call(varargin)
% Callback for GUI_24 pushbutton.
S = guidata(gcbf); % Get the structure.
set(0,'userdata',S); % Save it in the root.
f = make_subgui;
% If user closes gui_passdata, close new one as well because it will
% error when it tries to execute the callback otherwise.
set(S.fh,'deletefcn',{@fig_delet,f})
function [] = fig_delet(varargin)
% Executes when user closes gui_passdata.
try
delete(varargin{3})
catch
% Do nothing.
end
%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%SubGUI stuff...
function [f] = make_subgui()
f = figure('units','pixels',...
'menubar','none',...
'position',[750 510 200 100]); % Create a new GUI.
E = uicontrol('style','edit',...
'units','pixels',...
'position',[10 20 180 60],...
'string','Type something, press return.',...
'foregroundcolor','r',...
'callback',{@E_call});
pause(1.25)
S = get(0,'userdata');
str = get(S.ed,'string');
set(E,'string',str,'foregroundcolor','k')
uicontrol(E)
function [] = E_call(varargin)
% Callback for secondary GUI editbox.
S = get(0,'userdata');
set(S.ed,'string',get(gcbo,'string')) % Set gui_passdata editbox string.
close(gcbf) % Close SubGUI.
0 Kommentare
Firzi Mukhri
am 29 Mai 2013
This video gets me understand and solve this problem. Hope it helps you to. download submission. to view.
0 Kommentare
Sean de Wolski
am 9 Jun. 2011
To get you started.
To call a second GUI from the first, just call it's name subgui.m is the name of the subgui, in maingui.m
subgui
3 Kommentare
Sean de Wolski
am 9 Jun. 2011
So you want to set(handles.edit1,'string',num2str(c))
%example edit1 is name of edit box, c is the variable you pulled from appdata.
?
Nu9
am 17 Aug. 2011
HI, i am doing the same as you but i don´t understand how the second GUI saves the data from the edit text. i need to input 7 variables and then push a buttom to save the values and send it to the main GUI. the result is list off erros :/ i need to declare all the variables?and where a declare them?
0 Kommentare
Siehe auch
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!