Transfering data from GUI to main file

I have a GUI, call it GUI1, with two pushbuttons, the first pushbutton executes a series of calculations which are unimportant to this question, suffice to say the calculations require user input data to function. The second pushbutton in the original GUI opens a second GUI, call it GUI2, where users are prompted to input data that will be used in the calculations mentioned earlier. I need to make it so that data entered in GUI2, can be accessed for the calculations. It may be helpful to know that the file which creates the first GUI, also houses the code for the calculations, I do not call a seperate file, but have just written the calculations in, to activate on pressing of the first pushbutton. How can I make it so that the information enterred in the second GUI can be accessed in the calculations?

 Accepted Answer

Adam Danz
Adam Danz on 5 Aug 2019
Edited: Adam Danz on 6 Aug 2019
  1. Assign a unique tag to GUI2. This can be done by opening GUI2 in GUIDE, right click on the GUI background, select 'property inspector', and then assign a unique string in the "Tag" property.
  2. From GUI1, find the handle to GUI2 using: h = findobj(0, 'tag', 'UNIQUE_TAG'); where "UNIQUE_TAG" is the tag you assigned.
  3. Now get the handle to all of GUI2 components by using: handlesGUI2 = guidata(h);
  4. Now you have access to GUI2 from GUI1.
% Summary of above
% This goes in GUI1
h = findobj(0, 'tag', 'UNIQUE_TAG');
handlesGUI2 = guidata(h);
You should also write a conditional that throws an error when 'h' is empty (meaning that GUI2 could not be found) or if numel(h)>1 (meaning your tag was not unique enough or you have >1 instances of GUI2 open).

3 Comments

So, once I've done this, how do I access info from GUI2 in GUI1. To access info enterred in GUI1 I would just use something like get(handles.edit1,'String') etc. is it a similar process to access the info I've now stored in GUI1 from GUI2?
Ah so I guess I figured it out on my own, it's just instead of get(handles.whatever...) its get(handlesGUI2.whatever...)
Yes. Give it a try and you'll see that handlesGUI2 is the "handles" structure in GUI2.

Sign in to comment.

More Answers (0)

Categories

Find more on Creating, Deleting, and Querying Graphics Objects in Help Center and File Exchange

Products

Release

R2018a

Community Treasure Hunt

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

Start Hunting!