MATLAB: Passing data from GUI to .m file

guipassing data

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

Best Answer

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.