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!