MATLAB: Matrix Input Validation Help

arrayhelpinputMATLABstring

Hello,
I am trying to validate a user input as numeric while forcing the user to repeat if it is not. I currently have this working well as long as the user does not input a letter that is non numeric. I would like it to prompt the user again if they input a string instead of a number. Any help is appreciated.
Thanks
my input looks like
array(r, c) = str2num(input(['Digit for position ', num2str(c), ': '], 's'));
while array(r, c) > 6 || array(r, c) < 0
GUESS(r, c) = str2num(input(['Digit for position ', num2str(cc), ': '], 's'));
end

Best Answer

array(r, c) = str2double(input(['Digit for position ', num2str(c), ': '], 's'));
while isnan(array(r,c)) || array(r,c) ~= fix(array(r,c)) || array(r, c) < 0 || array(r, c) > 6
array(r, c) = str2double(input(['Digit for position ', num2str(cc), ': '], 's'));
end
or
array(r, c) = str2double(input(['Digit for position ', num2str(c), ': '], 's'));
while ~ismember(array(r,c), 0:6)
array(r, c) = str2double(input(['Digit for position ', num2str(cc), ': '], 's'));
end
Related Question