How can I modify and return variables between GUIs?

Hi, so I have come across different webpages describing similar problems but could not pin-point the origin of my project exactly.
Problem is as follow: suppose you have a main GUI that provides access to a certain algorithm that uses default parameters. Then you want to provide access to some kind of "Advanced Settings" for the expert user to change those parameters.
I am able to perform all these operations but, when it's time to close the second GUI and retrieve the updated values for the parameters, I only retrieve the default ones I have used to start the second GUI and not the user-updated ones.
Here you can find simplified code describing the problem: https://www.dropbox.com/sh/5215sfxhrqjml5c/52KiuVSFmZ
Thanks, Francesco

 Accepted Answer

You can pass them in the same way that functions pass variables around:
"Global" variables
Passing arguments
Putting the variables in the "userdata" of graphics objects. set(h,'Userdata',var)
Using a "current" file, where everything is passed around.

3 Comments

hi Iain, right now I am passing the variable as an argument (varargin) to the second GUI and I am trying to return the modified parameter in (varargout)to the first GUI.
In the code, I assign varargout{1} = get(handles.edit1,'String') where get() collects the text from the edit box "edit1". Unfortunately, the text that is passed back to the GUI_1 is the default string for GUI_2 and not the one that the user has modified.
I think it has to do with updating the handles in GUI_2 before retrieving the string in edit1, but I did perform guidata(hObject, handles) during the callback to the close button...
Any thoughts? Francesco
I think if you pass a handle from gui #1 into gui #2, so that the code in gui #2 has access to that handle you can pass it across with a set(h,'userdata',...).
I also think that you could write the second gui as a function, which can only complete when you close that gui, so that gui #1 just thinks that the call to generate gui #2 is long.
For the record I did solve the problem with global variables, although I would have preferred something more elegant.
Thanks

Sign in to comment.

More Answers (1)

Sorry, Francesco, reading and understanding your files would require much more time than I like to spend for an answer. Could you narrow down theproblem and specify in which part of which file the problem occurres?
Did you e.g. use the debugger by setting a breakpoint into the lines you expect to perform the wanted operations? Then stepping through the code line byb line will reveal, what's going on.

1 Comment

Hi Jan, thanks for dedicating to this problem whatever time you could spare.
I included GUIDE generated files to simplify the problem, and I am sympathetic of the fact that are kind of lengthy and kind of difficult to read. Let's see if I can simplify a bit
GUI_1 has edit1 and pushbutton1. Edit1 contains a string that can be edit, pushbutton1instead opens a second GUI identical GUI.
in GUI_2 the user inserts some text in the Edit1 and then uses pushbutton1 to close GUI_2 and have the newly inputed text appear in GUI_1.
All the data transfer works fine at this point but, when I call varargout{1} = get(handles.edit1,'String') in the OutputFcn of GUI_2 the default String for edit1 is returned, and not the one the user has changed.
I feel like is a simple problem of updating the text in edit1@GUI_2 so that when the OutputFcn is called, the retrieved text is the correct one, but it is somehow escaping me...
Thanks Francesco

Sign in to comment.

Categories

Tags

Asked:

on 6 Jun 2013

Community Treasure Hunt

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

Start Hunting!