查看单个帖子
旧 2019-12-14, 20:13   #1
poster
高级会员
 
注册日期: 2019-11-21
帖子: 3,008
声望力: 66
poster 正向着好的方向发展
帖子 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(Length>0,'Length is less than zero, exiting.') 看这里



更多&回答...
poster 当前离线   回复时引用此帖