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 Exchange에서 Creating, Deleting, and Querying Graphics Objects에 대해 자세히 알아보기

제품

릴리스

R2018a

질문:

2019년 8월 5일

댓글:

2019년 8월 6일

Community Treasure Hunt

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

Start Hunting!

Translated by