Closing MATLAB GUI application programmatically without using error() -
i trying make application/gui closes if user clicks cancel or exit of input dialog. tag of gui called window
using close(handles.window);
leads program looping through once , (after user clicks cancel or exit again) reaching close(handles.window);
line which, of course, leads invalid figure handle error.
is there method close application without need producing error , not closing entire matlab environment (like quit , exit). error() temporary fix works don't want application seem has crashed.
i have tried close has no effect. it's worth noting application reach inside if statement if user clicks cancel or exit.
i have tried setting variable , having close commands outside while loop.
apa = getavailablecomport(); aplist = ''; = 0; idx = 1:numel(apa) if == 0 aplist = apa(idx); else aplist = strcat(aplist, ', ', apa(idx)); end = + 1; end prompt = {'enter com port:'}; title = 'com port'; num_lines = 1; def = aplist; com_port = inputdlg(prompt,title,num_lines,def); % keep asking com port number until user gives valid 1 while sum(ismember(apa, com_port)) == 0 % if com port comes in available com ports @ least once % if user clicks cancel, close guide if isempty(com_port) == 1 error('closing...'); % here problem end prompt = {'invalid com port'}; title = 'invalid com port'; com_port = inputdlg(prompt,title,num_lines,def); end
the function getavailablecomport
found @ http://www.mathworks.com/matlabcentral/fileexchange/9251-get-available-com-port
this entire piece of code @ top of gui_openingfcn() function.
have tried putting break after close(handles.window). break exit while loop won't hit line again.
if isempty(com_port) == 1 close(handles.window) break end
this way while loop stops after closing window. if need more cleanup besides closing window set error flag .
%above while loop errorflag = false; if isempty(com_port) == 1 close(handles.window) errorflag = true; break end %outside of while loop if errorflag %do more clean-up / return / display error or warning end
also fyi, don't need isempty(com_port) == 1
... isempty(com_port)
return true/false without == 1
Comments
Post a Comment