MATLAB: GUI is remembering values entered last time it was open, how to stop this

errorguiinputmatlab gui

I have edit boxes and a push-button that takes their values and runs it through a different function (Some edit boxes don't need to be filled in depending the circumstances). I had used the GUI to test it and it worked fine but after closing it and running it again with some different values, I noticed that it was retrieving data that was in the boxes the last time I ran it and is causing a disruption in the code. I even decided to make it so that if the edit box is empty to make the value equal to 0 but it did not fix the problem! It is still somehow accessing previous values entered? Any idea what might be the problem?

Best Answer

Oh... global variables are used. You should NOT pass GUI data to other functions via global variables. Otherwise your GUI will memorize previous global values until it's cleared with clear global command in the OutputFcn or a CloseRequestFcn.
Looking at your other code, the better fix is to save your "global" variables as handle variable - you almost had it right. Here's an example of your popupmenu1:
function popupmenu1_Callback(hObject, eventdata, handles)
%global n %DELETE GLOBAL !
n=(get(hObject,'Value'))-1;
handles.n=n; %GOOD! Just need to save the handles now via guidata
guidata(hObject, handles)
%To use these "global" variable in another function, do:
n_value = handles.n;
You'll have to do a lot of similar edits to your code, but it'll be much better than using global.