mustBeSparse
Checks that an array is sparse.
Category: Programming > Functions
Syntax
mustBeSparse(A)
Checks that A is a sparse array. Returns nothing if the check passes and throws an error if not.
Description
mustBeSparse is a validator: it inspects its input and either returns silently or raises an error with the identifier MATLAB:validators:mustBeSparse. The error message states the requirement that was violated, so the caller sees what was expected rather than a generic failure.
A full array fails with a message saying the value must be sparse.
Input arguments
A- The value to check. Any array of the class the validator accepts.
Example
Full array fails
try
mustBeSparse([1 0 2])
catch err
disp(err.message)
end
Output
Value must be sparse.
Notes
MatLivre has no real sparse storage, so even sparse(...) results are reported as not sparse and fail this check.