mustBeNonsparse - Validate that value is nonsparse - MATLAB (original) (raw)
Main Content
Validate that value is nonsparse
Syntax
Description
mustBeNonsparse([value](#bvizfyp-A))
throws an error ifvalue
is sparse. If value
is empty, the function does not throw an error. This function does not return a value.
mustBeNonsparse
calls the issparse function to determine if the input is sparse.
Class support: All numeric classes, logical, and MATLABĀ® classes that overload issparse
.
Examples
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.
Value must not be sparse.
This class restricts 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 property 'Prop1' of class 'MyClass'. Value 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.
This function restricts the input argument to be any nonsparse value.
function mbNonsparse(S) arguments S {mustBeNonsparse} end disp(S) end
Calling this function with a sparse array results in an error thrown bymustBeNonsparse
.
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 (line 3) mbNonsparse(S) ^ Invalid argument at position 1. Value must not be sparse.
Input Arguments
Value to validate, specified as a scalar or array of any one of these types:
Other data types cause an error.
Data Types: single
| double
| int8
| int16
| int32
| int64
| uint8
| uint16
| uint32
| uint64
| logical
Complex Number Support: Yes
Tips
mustBeNonsparse
is designed to be used for property and function argument validation.
Extended Capabilities
The mustBeNonsparse
function fully supports GPU arrays. To run the function on a GPU, specify the input data as a gpuArray (Parallel Computing Toolbox). For more information, see Run MATLAB Functions on a GPU (Parallel Computing Toolbox).
Version History
Introduced in R2017a