Documentation

This is machine translation

Translated by Microsoft
Mouseover text to see original. Click the button below to return to the English verison of the page.

Note: This page has been translated by MathWorks. Please click here
To view all translated materals including this page, select Japan from the country navigator on the bottom of this page.

mustBeNonsparse

Validate that value is nonsparse or issue error

Syntax

mustBeNonsparse(A)

Description

example

mustBeNonsparse(A) issues an error if A is sparse. This function does not return a value.

mustBeNonsparse accepts user-defined objects if the class of the object implements this method:

Examples

collapse all

Use mustBeNonsparse to validate that the input is nonsparse.

Use the sparse function to create a sparse matrix.

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

Validate that S is nonsparse.

mustBeNonsparse(S)
Error using mustBeNonsparse (line 13)
Values must not be sparse.

This class constrains the value of Prop1 to nonsparse values.

classdef MyClass
   properties
      Prop1 {mustBeNonsparse}
   end
end

Create an object and assign a value to its property.

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.

When you assign a value to the property, MATLAB® calls mustBeNonsparse with the value being assigned to the property. mustBeNonsparse issues an error because the value assigned to Prop1 is sparse.

Input Arguments

collapse all

Value to validate, specified as a scalar or array of any one of the following:

Data Types: single | double | int8 | int16 | int32 | int64 | uint8 | uint16 | uint32 | uint64 | logical | char
Complex Number Support: Yes

Extended Capabilities

C/C++ Code Generation
Generate C and C++ code using MATLAB® Coder™.

Introduced in R2017a

Was this topic helpful?