matlab::data::SparseArray - Templated C++ class to access data in MATLAB sparse arrays - MATLAB (original) (raw)

Main Content

Templated C++ class to access data in MATLAB sparse arrays

Description

Use SparseArray objects to work with sparse MATLABĀ® arrays. To create a SparseArray, call createSparseArray in the ArrayFactory class.

Class Details

Template Parameters

T Type of element referred to, specified as:booldoublestd::complexsingle _(since R2025a)_std::complex (since R2025a)

Constructors

Copy Constructors

SparseArray(const SparseArray<T>& rhs)

SparseArray(const Array& rhs)

Description

Creates a shared data copy of a SparseArray object.

Parameters

const SparseArray& rhs Value to copy.
const Array& rhs Value specified as Array ofArrayType::SPARSE_LOGICAL,ArrayType::SPARSE_DOUBLE, orArrayType::SPARSE_COMPLEX_DOUBLE.

Throws

matlab::data::InvalidArrayTypeException Type of input Array is not sparse.

Copy Assignment Operators

SparseArray& operator=(const SparseArray<T>& rhs)

SparseArray& operator=(const Array& rhs)

Description

Assigns a shared data copy to a SparseArray object.

Parameters

const SparseArray& rhs Value to copy.
const Array& rhs Value specified as Array of type ArrayType::SPARSE_LOGICAL,ArrayType::SPARSE_DOUBLE, orArrayType::SPARSE_COMPLEX_DOUBLE.

Returns

SparseArray& Updated instance.

Throws

matlab::data::InvalidArrayTypeException Type of input Array is not sparse.

Move Constructors

SparseArray(SparseArray&& rhs)

Description

Moves contents of a SparseArray object to a new instance.

Parameters

const SparseArray& rhs Value to move.
const Array& rhs Value specified as Array of type ArrayType::SPARSE_LOGICAL,ArrayType::SPARSE_DOUBLE, orArrayType::SPARSE_COMPLEX_DOUBLE.

Throws

matlab::data::InvalidArrayTypeException Type of input Array is not sparse.

Move Assignment Operators

SparseArray& operator=(SparseArray<T>&& rhs)

SparseArray& operator=(Array&& rhs)

Description

Assigns the input to this SparseArray object.

Parameters

const SparseArray& rhs Value to move.
const Array& rhs Value specified as Array of type ArrayType::SPARSE_LOGICAL,ArrayType::SPARSE_DOUBLE, orArrayType::SPARSE_COMPLEX_DOUBLE.

Returns

SparseArray& Updated instance.

Throws

matlab::data::InvalidArrayTypeException Type of input Array is not sparse.

Iterators

Begin Iterators

const_iterator begin() const

const_iterator cbegin() const

Returns

iterator Iterator to beginning of array, specified asTypedIterator.
const_iterator Iterator, specified asTypedIterator<typename std::add_const::type>.

End Iterators

const_iterator end() const

const_iterator cend() const

Returns

iterator Iterator to end of array, specified asTypedIterator.
const_iterator Iterator, specified asTypedIterator<typename std::add_const::type>.

Member Functions

getNumberOfNonZeroElements

size_t getNumberOfNonZeroElements() const

Description

Returns the number of nonzero elements in the array.

Returns

size_t Number of nonzero elements in array.

getIndex

SparseIndex getIndex(const TypedIterator& it)

SparseIndex getIndex(const TypedIterator& it)

Description

Returns the row-column coordinates of the nonzero entry that the iterator is pointing to.

Parameters

const TypedIterator& it Iterator pointing to current entry in sparse matrix.
const TypedIterator& it

Returns

SparseIndex Row-column coordinates of nonzero entry that iterator points to. SparseIndex is defined as std::pair<size_t, size_t>.

Version History

Introduced in R2017b

expand all

You can create single-precision sparse matrices withmatlab.data.SparseArray.