I created a GUI (did not use GUIDE) to ask the user for input. Initially, the script kept running while the GUI was open and before the user had a chance to enter anything. This was solved using uiwait(fig1). Now, the script waits until the user has entered the data and clicks continue, but once the user clicks continue, the GUI does not close until the rest of the scrip has run, which takes some time. It makes it look like MATLAB crashed when it didn't. Am I missing something about uiwait or uiresume?
Any help would be greatly appreciated! Thanks!
Here's the GUI code:
function GUI_getFuelData% Enter fuel information.
% Create GUI figure
[Input fields/fig left out for readability sake]% Continue button
pButton = uicontrol('Parent',fig1,... 'Style','pushbutton',... 'String','Continue',... 'Units','pixels',... 'Position',[135 10 60 30],... 'Callback', @pButtonCallback); %%Update GUI
movegui(fig1,'center') % Make the GUI visible.
set(fig1,'Visible','on'); uiwait(fig1); %%Callback
function pButtonCallback(hObject, eventdata) % Callback function to retrieve entered data and continue the
% program.
dieselCost = str2double(get(hDieselCostEdit, 'String')); dieselLHV = str2double(get(hDieselLHVEdit, 'String')); dieselDensity = str2double(get(hDieselDensityEdit, 'String')); assignin('base', 'dieselCost', dieselCost); assignin('base', 'dieselLHV', dieselLHV); assignin('base', 'dieselDensity', dieselDensity); natGasCost = str2double(get(hNatGasCostEdit, 'String')); natGasLHV = str2double(get(hNatGasLHVEdit, 'String')); natGasDensity = str2double(get(hNatGasDensityEdit, 'String')); assignin('base', 'natGasCost', natGasCost); assignin('base', 'natGasLHV', natGasLHV); assignin('base', 'natGasDensity', natGasDensity); close(fig1); end end
Best Answer