Main Content

mustBeNonsparse

验证值为非稀疏值

说明

示例

如果 value 为稀疏值,mustBeNonsparse(value) 将引发错误。如果 value 为空,则该函数不会引发错误。此函数不返回值。

mustBeNonsparse 调用 issparse 函数来确定输入是否为稀疏。

支持的类:重载 issparse 的所有数值类、logical 和 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 会使用赋给属性的值调用 mustBeNonsparsemustBeNonsparse 将引发错误,因为赋给 Prop1 的值为稀疏值。

此函数将输入参量限制为非稀疏值。

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.

输入参数

全部折叠

要验证的值,指定为标量或由以下任一类型的值组成的数组:

其他数据类型会导致错误。

数据类型: single | double | int8 | int16 | int32 | int64 | uint8 | uint16 | uint32 | uint64 | logical
复数支持:

提示

  • mustBeNonsparse 用于属性和函数参量验证。

扩展功能

C/C++ 代码生成
使用 MATLAB® Coder™ 生成 C 代码和 C++ 代码。

版本历史记录

在 R2017a 中推出