matlab::data::Array - C++ base class for all array types - MATLAB (original) (raw)

Main Content

C++ base class for all array types

Description

Use Array objects to represent single and multi-dimensional arrays. TheArray class provides methods to get generic information about all arrays, such as dimensions and type. The class has methods to create both deep (cloned) copies and shared data copies and supports copy-on-write semantics.

To construct Array objects, use ArrayFactory methods.

Class Details

Namespace: matlab::data
Include: MDArray.hpp

Constructors

Default Constructor

Copy Constructors

Description

Creates a shared data copy of an Array object.

Parameters

const Array& rhs Value to copy.

Copy Assignment Operators

Array& operator=(const Array& rhs)

Description

Assigns a shared data copy to an Array object.

Parameters

const Array& rhs Value to copy.

Move Constructors

Description

Moves contents of an Array object to a new instance.

Parameters

Array&& rhs Value to move.

Move Assignment Operators

Array& operator=(Array&& rhs)

Description

Assigns the input to this Array object.

Parameters

Array&& rhs Value to move.

Destructor

Indexing Operators

operator[]

ArrayElementRef<false> operator[](size_t idx)

ArrayElementRef<true> operator[](size_t idx) const

Description

Enables [] indexing on const and non-const arrays. Indexing is 0-based.

Parameters

size_t idx First array index

Returns

ArrayElementRef Temporary object containing the index specified. The return value allows the element of the array to be modified or retrieved.
ArrayElementRef Temporary object containing the index specified. The return value allows the element of the array to be retrieved, but not modified.

Member Functions

getType

ArrayType getType() const

getMemoryLayout

MemoryLayout getMemoryLayout() const

Returns

MemoryLayout Memory layout for array, specified asMemoryLayout::COLUMN_MAJOR orMemoryLayout::ROW_MAJOR.

Throws

matlab::data::FeatureNotSupportedException Arrays created before R2019a did not support different memory layouts. The memory layout was always column-major.

getDimensions

ArrayDimensions getDimensions() const

Returns

ArrayDimensions Vector of each dimension in array.

getNumberOfElements

size_t getNumberOfElements() const

Returns

size_t The number of elements in array.

isEmpty

Returns

bool True if array is empty. False if array is not empty.

Free Functions

getReadOnlyElements

template Range<TypedIterator, T const> getReadOnlyElements(const Array& arr)

Description

Get a range containing the elements of the Array. Iterators contained in the range are const.

Returns

Range<TypedIterator, T const> Range containing begin andend iterators for inputArray.

Throws

matlab::data::InvalidArrayTypeException Array does not contain typeT.

getWritableElements

template Range<TypedIterator, T> getWritableElements(Array& arr)

Description

Get a range containing the elements of the Array. Iterators contained in the range are non-const.

Returns

Range<TypedIterator, T> Range containing begin andend iterators for inputArray.

Throws

matlab::data::InvalidArrayTypeException Array does not contain typeT.

Version History

Introduced in R2017b

expand all

You can create and iterate through the data of amatlab::data::Array in either row-major or column-major order.

You can create an _N_-Dmatlab::data::Array object with row-major memory layout. Previously, the createArrayFromBuffer function created row-major arrays only in 2-D. To create a matlab::data::Array object with row-major memory layout, set the createArrayFromBuffer argumentmemoryLayout to MemoryLayout::ROW_MAJOR. To determine the memory layout for an existing matlab::data::Array object, call getMemoryLayout.

Create a matlab::data::Array with data memory layout specified as column-major (default) or row-major. For more information, see thememoryLayout parameter increateArrayFromBuffer. To determine the memory layout for an existing matlab::data::Array, callgetMemoryLayout.