passing values between guis?
이전 댓글 표시
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.
채택된 답변
추가 답변 (1개)
Paulo Silva
2011년 6월 6일
doc setappdata %use h=0 to store the data in the base workspace
댓글 수: 1
Sean de Wolski
2011년 6월 9일
It's not the base workspace, but the root directory. The root directory contains all of the settings for MATLAB etc. so it can be dangerous. As long as you use fancy names for the variables (especially: underscores, numbers) it should be safe.
카테고리
도움말 센터 및 File Exchange에서 Structures에 대해 자세히 알아보기
제품
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!