MATLAB: Read inputs from GUI into a second master script

guiguidehandles

Hi,
I am trying to read inputs from a basic GUI made in GUIDE, save them as doubles, then use them in subsequent analysis. I can't seem to use the defined inputs in my main file with error: Undefined function or variable 'dt'.
Fairly new to MatLAB and my first GUI. My code is currently:
% --- Executes on button press in RUN.
function RUN_Callback(hObject, eventdata, handles)
% hObject handle to RUN (see GCBO)
% eventdata reserved - to be defined in a future version of MATLAB
% handles structure with handles and user data (see GUIDATA)
% Save Handles
guidata(hObject,handles);
% Save Inputs
service_period = str2double(get(handles.Service_Period, 'String'))
no_of_runs = str2double(get(handles.no_of_runs,'String'))
dt = str2double(get(handles.dt, 'String'))
% Change run button to running
set(handles.RUN, 'String', 'Running')
% Run analysis
runBen3
Any ideas what I'm doing wrong?
Thanks
Ben

Best Answer

To put the summary of all this in an answer.
Think what you are doing before just always putting any or all of the following in a script:
clear
clear all
close all
etc.
If you are expecting to have variables defined in a GUI then clearing them all at the start of your script is not very useful.
If you used a function instead of a script you wouldn't feel the need to do this at all as each function has its own workspace and doesn't retain all the detritus from whatever workspace it was called from (nor does it pollute said workspace with its own variables once it has completed!)