2011-02-07 324 views
4

驗證輸入或退出程序的錯誤信息altoghether有什麼好方法?Matlab - 輸入驗證

例如,如果我需要輸入諸如

Length = input('\nEnter a length in feet: '); 

如何檢查,如果數字是大於0

if Length > 0 then 
    %%do code 
else 
%%Output error 
%%nothing to do here so it just continues and exits 
end 

回答

5

我使用斷言:

assert(Length>0,'Length is less than zero, exiting.') 

here

3

您可以使用內置的功能assert(類型doc asserthelp assert

assert(Length > 0, 'your error msg')