Hello,
is there any (simple) way to set up that an input can contain ONLY values from an interval (not necessarily of integers)?
Something such as:
abc=input('Choose a number from <-1000;999>: ') while abc<1000||abc>999 abc=input('Wrong! Choose again a number from <-1000;999>: ')
works good, when I answer outside the interval. However, when I answer with a letter or with nothing typed at all – just clicking on enter button, I get these error messages:
??? Error using ==> inputUndefined function or variable '_that letter_'.
or
??? Error: Unexpected MATLAB expression.
for the letters. And:
??? Operands to the || and && operators must be convertible to logical scalar values.Error in ==> blah at 12while abc<-1000||abc>999
while no typing an answer at all. I want to make it idiotproof as much as possible.
I guess I am not even taking into account typing more inputs (probably nargin>1; error('… :'?). That could actually sort out the latter, too via nargin<1, right?
Best Answer