2012-04-04 106 views
1

我想讓matlab獲取用戶輸入但接受兩個字母的例子。例如,我有:Matlab正則表達式if語句

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 

if語句顯然是行不通的,但基本上我想接受一個小寫或uppcase Y.最新最好的方式做到這一點?

回答

5

使用函數lowerupper。例如:

if (lower(reply) == 'y') 

或者,strcmpi將比較字符串不區分大小寫。例如: -

if (strcmpi(reply, 'y'))