验证输入或退出程序的错误信息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
验证输入或退出程序的错误信息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
您可以使用内置的功能assert
(类型doc assert
或help assert
)
assert(Length > 0, 'your error msg')
你可以做更高级的使用Matlab的功能正则表达式输入字符串检查Matlabs:
http://www.mathworks.com/help/techdoc/ref/regexp.html
例如,这可以让您确保输入字符串中只有数字字符。
Input Parser由MATLAB作为全功能函数输入“验证器”提供。