MATLAB爱好者论坛-LabFans.com

MATLAB爱好者论坛-LabFans.com (https://www.labfans.com/bbs/index.php)
-   资料存档 (https://www.labfans.com/bbs/forumdisplay.php?f=72)
-   -   Matlab-输入验证 (https://www.labfans.com/bbs/showthread.php?t=26296)

poster 2019-12-14 20:13

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

[B]回答:[/B]

我用断言:

assert(Length>0,'Length is less than zero, exiting.') 看[URL="http://www.mathworks.com/help/techdoc/ref/assert.html"]这里[/URL]



[url=https://stackoverflow.com/questions/4919561]更多&回答...[/url]


所有时间均为北京时间。现在的时间是 05:06

Powered by vBulletin
版权所有 ©2000 - 2025,Jelsoft Enterprises Ltd.