- Launch test2
- Click the push button. This launches a new GUI, test1. Further it(test2) reads the stored value in the test1's edit box. Initially it is empty.
- In the test1 edit box enter a number say 123.
- Hit the push button in test1. This saves the data in the edit box with the edit box's handle in test1.
- Again hit the push button in test2 to show the data entered in test1.
Get values from another GUI using handles or getapp / setapp
3 次查看(过去 30 天)
显示 更早的评论
Hi,
I'm trying to make a program which opens up a gui (test2), then calls for a new gui(Test1) by clicing a pushbutton. From the Test1 gui i want to store some values written in editable textboxes. After setting the values, i want to go back to the main gui (test2) and push another pushbutton to start some calculations using the values from Test1.
I know how to do it with globals, but I understand this is not a preffered way to do things.
This is the code so far, but it's not working. What am I doing wrong here? Please don't link the FAQs.
%This is the code for Test1 gui
function pushbutton1_Callback(hObject, eventdata, handles)
% hObject handle to pushbutton1 (see GCBO)
% eventdata reserved - to be defined in a future version of MATLAB
% handles structure with handles and user data (see GUIDATA)
x2 =str2double(get(handles.edit1, 'String'));
setappdata(handles.gui1,'x2', x2);
guidata(hObject,handles);
% This is the code for test2 gui
function pushbutton2_Callback(hObject, eventdata, handles)
% hObject handle to pushbutton2 (see GCBO)
% eventdata reserved - to be defined in a future version of MATLAB
% handles structure with handles and user data (see GUIDATA)
h = findobj('Tag', 'gui1');
x4 = getappdata(h, 'x2');
set(handles.edit1, 'String', x4);
Thanks.
0 个评论
回答(2 个)
sam0037
2016-2-17
Hi,
There are multiple ways of sharing data between GUIs. To illustrate one of the ways, I have created test1 and test2 GUIs and are attached here. I understand the following is what you are expecting:
Go through the callbacks in the attached GUIs namely test1 and test2 for a better understanding.
If you would like to know more about other ways of sharing data between UI callbacks, refer to the following link:
0 个评论
Charly Parker
2016-2-22
I can´t download the file test.1.fig and test.2.fig . would you like to update again? Thank you!
0 个评论
另请参阅
类别
在 Help Center 和 File Exchange 中查找有关 Migrate GUIDE Apps 的更多信息
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!