Passing data from GUI to .m file

5 views (last 30 days)
Hossein G
Hossein G on 3 Sep 2014
Commented: Hossein G on 3 Sep 2014
Hello.I made a code(.m file) that accepts some inputs from user and gives a file as an output.Now I decided to make it receive inputs by means of GUI.A GUI composed of six textboxes and one push button for submitting inputs and receiving output.I have problem that how I can pass variables(inputs)from GUI to .m file Here is code Thanks a lot

Accepted Answer

Adam
Adam on 3 Sep 2014
Edited: Adam on 3 Sep 2014
Where you put, for example
k.name=get(hObject,'String')
in a callback, k there is just a local variable. As such it goes out of scope as soon as the callback completes.
What you need to do is attach this to the handles structure of the GUI, something more like:
handles.k.name = get( hObject, 'String' )
guidata( hObject, handles );
That last line is important to always include otherwise your changes to the handles structure will also be local to the callback function and lost after it completes.
Obviously you then also need to update your final callback equivalently:
ff=redesign( handles.k )
If you prefer you can ignore the text/edit box callbacks altogether and just collect up all the components from the UI under your pushbutton callback. That is often preferable if you do not need real time updating of the parameters in the underlying storage - i.e. if you are only going to use the values current at the time of clicking the pushbutton and don't care if the user changes their mind 27 times on what values they enter on the UI.
  5 Comments
Adam
Adam on 3 Sep 2014
Edited: Adam on 3 Sep 2014
Under your "Submit" button callback just add instructions to the effect of:
set( handles.text1, 'String', '' )
for all your text boxes, where 'text1' should be replaced by whatever tag you gave to your text boxes.
I would probably create a function called resetTextBoxes( handles ) or similar and do it in there, but that's just me being fussy. If you only have a 6 of them then just 6 statements in a row like the one above works.
Hossein G
Hossein G on 3 Sep 2014
Again Thanks a lot Adam

Sign in to comment.

More Answers (0)

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!