I want to have matlab take user input but accept both cases of a letter. For example I have:
function nothing = checkGC(gcfile)
if exist(gcfile)
reply = input('file exists, would you like to overwrite? [Y/N]: ', 's');
if (reply == [Yy])
display('You have chosen to overwrite!')
else
$ Do nothing
end
end
The if statement obviously doesn't work, but basically I want to accept a lowercase or uppcase Y. Whats the best way to do this?
Simply use a basic or operator in your condition. Check the documentation here: http://www.mathworks.se/help/techdoc/ref/logicaloperatorselementwise.html
http://www.mathworks.de/help/techdoc/ref/regexpi.html
if (regexpi(reply,'^y(es)?$'))
display('You have chosen to overwrite!')