Get values from another GUI using handles or getapp / setapp

3 views (last 30 days)
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.

Answers (2)

sam0037
sam0037 on 17 Feb 2016
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:
  1. Launch test2
  2. 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.
  3. In the test1 edit box enter a number say 123.
  4. Hit the push button in test1. This saves the data in the edit box with the edit box's handle in test1.
  5. Again hit the push button in test2 to show the data entered in test1.
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:

Charly Parker
Charly Parker on 22 Feb 2016
I can´t download the file test.1.fig and test.2.fig . would you like to update again? Thank you!

Categories

Find more on Migrate GUIDE Apps in Help Center and File Exchange

Community Treasure Hunt

Find the treasures in MATLAB Central and discover how the community can help you!

Start Hunting!