2011-02-07 107 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')