matlab - Error handling with inputdlg -


below input dialog box i'm using in program. know how "nicely" handle case when user input not number? also, if number outside range minlev - maxlev error dialog pops up, cannot press ok button because input dialog pops in front of it. know how fix this?

rvp= 1;   while ( rvp )  prompt = {'enter corridor width (1050-1400mm) :'};  dlg_title = 'input';  num_lines=1;  answer = inputdlg(prompt,dlg_title,num_lines);      if(str2num(answer{1})<1050 || (str2num(answer{1})>1400))        errordlg('number out of range');      else          w1 = (2*answer{1}-1050-1400)/(1400-1050)       end end 

use isnumeric. can re-call inputdlg after error dialog.

to keep errordlg box being covered up, use uiwait.

while ( rvp )     prompt = {'enter corridor width (1050-1400mm) :'};     dlg_title = 'input';     num_lines=1;     answer = inputdlg(prompt,dlg_title,num_lines);     if ~isnumeric(answer) || (str2num(answer{1})<1050 || (str2num(answer{1})>1400))         uiwait(errordlg('number out of range'));         answer = inputdlg({'please enter valid input (1050-1400mm) :'},...                           dlg_title,num_lines);     end         w1 = (2*answer{1}-1050-1400)/(1400-1050) end 

Comments

Popular posts from this blog

c# - Send Image in Json : 400 Bad request -

jquery - Fancybox - apply a function to several elements -

An easy way to program an Android keyboard layout app -