2011-02-07 16 views
4

入力を検証するか、エラーメッセージが表示された状態でプログラムを終了するには良い方法はありますか?Matlab - 入力検証

私はアサートを使っ0より大きい

何か

if Length > 0 then 
    %%do code 
else 
%%Output error 
%%nothing to do here so it just continues and exits 
end 

答えて

5

のように、私は数があるかどうかを確認するにはどうすればよいの入力など

Length = input('\nEnter a length in feet: '); 

を取るたとえば

assert(Length>0,'Length is less than zero, exiting.') 

は、あなたが、正規表現のためのMatlabの関数を使用して、入力文字列に、より高度なチェックを行うことができます

assert(Length > 0, 'your error msg') 
1

あなたが機能assert(タイプdoc assertまたはhelp assert)に建てられたMatlabsを使用することができますhere

3

Input Parserは、本格的な関数入力 'バリデータ'としてMATLABによって提供されています。