poster
2019-12-14, 20:13
验证输入或退出程序并同时显示错误消息的好方法是什么?
例如,如果我输入
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(Length>0,'Length is less than zero, exiting.') 看这里 (http://www.mathworks.com/help/techdoc/ref/assert.html)
更多&回答... (https://stackoverflow.com/questions/4919561)
例如,如果我输入
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(Length>0,'Length is less than zero, exiting.') 看这里 (http://www.mathworks.com/help/techdoc/ref/assert.html)
更多&回答... (https://stackoverflow.com/questions/4919561)