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?

 採用された回答

Adam Danz
Adam Danz 2019 年 8 月 5 日
編集済み: Adam Danz 2019 年 8 月 6 日

0 投票

  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 件のコメント

Adam Cutright
Adam Cutright 2019 年 8 月 6 日
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?
Adam Cutright
Adam Cutright 2019 年 8 月 6 日
Ah so I guess I figured it out on my own, it's just instead of get(handles.whatever...) its get(handlesGUI2.whatever...)
Adam Danz
Adam Danz 2019 年 8 月 6 日
Yes. Give it a try and you'll see that handlesGUI2 is the "handles" structure in GUI2.

サインインしてコメントする。

その他の回答 (0 件)

カテゴリ

ヘルプ センター および File ExchangeCreating, Deleting, and Querying Graphics Objects についてさらに検索

製品

リリース

R2018a

Community Treasure Hunt

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

Start Hunting!

Translated by