Main Content

mustBeNonsparse

値が非スパースであることを検証

説明

mustBeNonsparse(value) は、value がスパースである場合にエラーをスローします。value が空である場合、関数はエラーをスローしません。この関数は値を返しません。

mustBeNonsparse は、関数 issparse を呼び出して、入力がスパースかどうかを判別します。

クラス サポート: すべての数値クラス、logical、および issparse をオーバーロードする MATLAB® クラス。

すべて折りたたむ

mustBeNonsparse を使用して、入力が非スパースであることを検証します。

スパース行列の作成には関数 sparse を使用します。

A = [ 0   0   0   5
      0   2   0   0
      1   3   0   0
      0   0   4   0];
S = sparse(A);

S が非スパースであることを検証します。

mustBeNonsparse(S)
Values must not be sparse.

このクラスは Prop1 の値を非スパース値に制限します。

classdef MyClass
   properties
      Prop1 {mustBeNonsparse}
   end
end

オブジェクトを作成して、プロパティに値を割り当てます。

obj = MyClass;
A = [ 0   0   0   5
      0   2   0   0
      1   3   0   0
      0   0   4   0];
obj.Prop1 = sparse(A);
Error setting 'Prop1' property of 'MyClass' class:
Values must not be sparse.

プロパティに値を割り当てると、MATLAB はプロパティに割り当てた値を使用して mustBeNonsparse を呼び出します。Prop1 に割り当てられた値がスパースであるため、mustBeNonsparse はエラーを発行します。

この関数は、入力引数を任意の非スパース値に制限します。

function mbNonsparse(S)
    arguments
        S {mustBeNonsparse}
    end
    disp(S)
end

スパース配列を指定してこの関数を呼び出すと、mustBeNonsparse によってエラーがスローされます。

A = [ 0   0   0   5
      0   2   0   0
      1   3   0   0
      0   0   4   0];
S = sparse(A);
mbNonsparse(S)
Error using mbNonsparse
 mbNonsparse(S)
             ↑
Invalid input argument at position 1. Value must not be sparse.

入力引数

すべて折りたたむ

検証する値。スカラー、または次のいずれかの型の配列として指定します。

  • logical または数値クラス

  • issparse をオーバーロードする MATLAB クラス

他のデータ型の場合、エラーが発生します。

データ型: single | double | int8 | int16 | int32 | int64 | uint8 | uint16 | uint32 | uint64 | logical
複素数のサポート: あり

ヒント

  • mustBeNonsparse は、プロパティと関数の引数の検証で使用されるように設計されています。

拡張機能

C/C++ コード生成
MATLAB® Coder™ を使用して C および C++ コードを生成します。

バージョン履歴

R2017a で導入