ヘルプ センターヘルプ センター
値が数値または logical であることを検証
mustBeNumericOrLogical(value)
例
mustBeNumericOrLogical(value) は、value が数値と logical のいずれでもない場合にエラーをスローします。この関数は値を返しません。
value
mustBeNumericOrLogical は以下の関数を呼び出して、入力が数値または logical であるかどうかを判別します。
mustBeNumericOrLogical
isnumeric
islogical
この関数は空の値である入力引数を無視します。このため、プロパティ値または関数の引数値が空の場合、エラーはスローされません。
すべて折りたたむ
オブジェクト プロパティの値が数値または論理値であることを検証します。
a = lettersPattern; mustBeNumericOrLogical(a)
Values must be numeric or logical.
この場合、a プロパティの値は pattern オブジェクトなので、エラーが発生します。
a
pattern
このクラスは Prop1 の値を数値に制限します。
Prop1
classdef MyClass properties Prop1 {mustBeNumericOrLogical} end end
オブジェクトを作成して、プロパティに値を割り当てます。
obj = MyClass; obj.Prop1 = get(gca,'Visible');
Error setting 'Prop1' property of 'MyClass' class: Values must be numeric or logical.
プロパティに値を割り当てると、MATLAB® はプロパティに割り当てた値を使用して mustBeNumericOrLogical を呼び出します。Prop1 に割り当てられた値が char ベクトルであるため、mustBeNumericOrLogical はエラーを発行します。
char
この関数は、入力引数を数値ベクトルまたは logical ベクトルに制限します。
function r = mbNumericOrLogical(x) arguments x (1,:) {mustBeNumericOrLogical} end p = [3 2 1]; r = polyval(p,x); end
文字ベクトルを指定してこの関数を呼び出すと、mustBeNumericOrLogical によってエラーがスローされます。
x = '4 3 2'; r = mbNumericOrLogical(x);
Error using mbNumericOrLogical r = mbNumericOrLogical(x); ↑ Invalid input argument at position 1. Value must be numeric or logical.
検証する値。スカラーまたは次のいずれかの配列として指定します。
logical または数値クラス
logical
isnumeric または islogical を実装する MATLAB クラス
データ型: single | double | int8 | int16 | int32 | int64 | uint8 | uint16 | uint32 | uint64 | logical 複素数のサポート: あり
single
double
int8
int16
int32
int64
uint8
uint16
uint32
uint64
mustBeNumericOrLogical は、プロパティと関数の引数の検証で使用されるように設計されています。
mustBeNumeric | arguments
mustBeNumeric
arguments
次の MATLAB コマンドに対応するリンクがクリックされました。
コマンドを MATLAB コマンド ウィンドウに入力して実行してください。Web ブラウザーは MATLAB コマンドをサポートしていません。
Choose a web site to get translated content where available and see local events and offers. Based on your location, we recommend that you select: .
You can also select a web site from the following list:
Select the China site (in Chinese or English) for best site performance. Other MathWorks country sites are not optimized for visits from your location.
Contact your local office