MATLAB: Passing values between guis

guiguideMATLAB

hey
i am building a gui that calls another gui.
1. i enter data into my main gui
2. then i press a pushbutton to call the sub gui
3. then i display the data got from the main gui in my sub gui.this happens upon the press of a push button.
right until this step everything seems to be working ok. i used the following code, which i got off http://blinkdagger.com/matlab/matlab-gui-how-to-easily-share-data-between-two-separate-guis/
code:
function pushbuttongetparams_Callback(hObject, eventdata, handles)
% hObject handle to pushbuttongetparams (see GCBO)
% eventdata reserved - to be defined in a future version of MATLAB
% handles structure with handles and user data (see GUIDATA)
mainguiFigureHandle = maingui; %stores the figure handle of main GUI here
%stores the GUI data from main GUI here
%now we can access any of the data from main GUI!!!!
mainData = guidata(mainguiFigureHandle);
%store the input text from main GUI
%into the variable maingui_input
maingui_input = get(mainguiData.primetext,'String');
%set the static text on subgui GUI to match the
%input text from maingui GUI
set(handles.primetxt2,'String',maingui_input);
my problem is that everytime i press the pushbutton on the subgui to retrieve data from the maingui, the maingui pops open too! after which i have to go back to the subgui by toggling the windows. how do i get rid of this?
i have tried using set(0,’CurrentFigure’,secondGUIname) but that does not work. is there a simple way to get rid of this problem? hopefully something that does not involve global variables or structures or even more lines of code(!) etc.!
p.s. i have gone through the other answers on the site, and none of them seem to be working for me.

Best Answer

I assume your main gui is called maingui? If so, then this line:
mainguiFigureHandle = maingui;
is what is creating another maingui. I would get rid of this line and alter the next to:
mainData = guidata(gcbf);
I also assume that somewhere along the way you have stored the handle to the subgui textbox in the handles structure as primetxt2...