mustBeNonpositive
値が非正であることを検証
説明
例
値が正でないことを検証
mustBeNonpositive
を使用して、入力に非正の値のみが含まれていることを検証します。
A = 1 < 10; mustBeNonpositive(A)
Value must not be positive.
式 1 < 10
は logical 1
を返すため、A
の値は正で、mustBeNonpositive
はエラーを発行します。
プロパティ値の制限
このクラスは、Prop1
の値を非正の値に制限します。
classdef MyClass properties Prop1 {mustBeNonpositive} end end
オブジェクトを作成して、プロパティに値を割り当てます。
obj = MyClass; obj.Prop1 = 10;
Error setting property 'Prop1' of class 'MyClass': Value must not be positive.
プロパティに値を割り当てると、MATLAB はプロパティに割り当てた値を使用して mustBeNonpositive
を呼び出します。値 10
は正であるため、mustBeNonpositive
はエラーを発行します。
関数の引数値の制限
この関数は、2 つの入力引数を宣言します。入力 lower
は正であってはならず、入力 upper
は正でなければなりません。
function r = mbNonpositive(lower,upper) arguments lower {mustBeNonpositive} upper {mustBePositive} end x = lower*pi:upper*pi; r = sin(x); end
mustBeNonpositive
の要件を満たさない lower
の値を指定して関数を呼び出すと、エラーになります。
r = mbNonpositive(2,4);
Error using mbNonpositive r = mbNonpositive(2,4); ↑ Invalid input argument at position 1. Value must not be positive.
入力引数
ヒント
mustBeNonpositive
は、プロパティと関数の引数の検証で使用されるように設計されています。
拡張機能
C/C++ コード生成
MATLAB® Coder™ を使用して C および C++ コードを生成します。
GPU 配列
Parallel Computing Toolbox™ を使用してグラフィックス処理装置 (GPU) 上で実行することにより、コードを高速化します。
この関数は GPU 配列を完全にサポートしています。詳細については、GPU での MATLAB 関数の実行 (Parallel Computing Toolbox)を参照してください。
分散配列
Parallel Computing Toolbox™ を使用して、クラスターの結合メモリ上で大きなアレイを分割します。
この関数は分散配列を完全にサポートしています。詳細については、分散配列を使用した MATLAB 関数の実行 (Parallel Computing Toolbox)を参照してください。
バージョン履歴
R2017a で導入
MATLAB コマンド
次の MATLAB コマンドに対応するリンクがクリックされました。
コマンドを MATLAB コマンド ウィンドウに入力して実行してください。Web ブラウザーは MATLAB コマンドをサポートしていません。
Select a Web Site
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:
How to Get Best Site Performance
Select the China site (in Chinese or English) for best site performance. Other MathWorks country sites are not optimized for visits from your location.
Americas
- América Latina (Español)
- Canada (English)
- United States (English)
Europe
- Belgium (English)
- Denmark (English)
- Deutschland (Deutsch)
- España (Español)
- Finland (English)
- France (Français)
- Ireland (English)
- Italia (Italiano)
- Luxembourg (English)
- Netherlands (English)
- Norway (English)
- Österreich (Deutsch)
- Portugal (English)
- Sweden (English)
- Switzerland
- United Kingdom (English)