This is machine translation

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

Note: This page has been translated by MathWorks. Click here to see
To view all translated materials including this page, select Country from the country navigator on the bottom of this page.

matlab::data::Array

C++ base class for all array types

Description

Use Array objects to represent single and multi-dimensional arrays. The Array 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

Array()

Throws

None

Copy Constructors

Array(const Array& rhs)

Description

Creates a shared data copy of an Array object.

Parameters

const Array& rhs

Value to copy.

Throws

None

Copy Assignment Operators

Array& operator=(const Array& rhs)

Description

Assigns a shared data copy to an Array object.

Parameters

const Array& rhsrhs

Value to copy.

Returns

Array&

Updated instance.

Throws

None

Move Constructors

Array(Array&& rhs)

Description

Moves contents of an Array object to a new instance.

Parameters

Array&& rhs

Value to move.

Throws

None

Move Assignment Operators

Array& operator=(Array&& rhs)

Description

Assigns the input to this Array object.

Parameters

Array&& rhs

Value to move.

Returns

Array&

Updated instance.

Throws

None

Destructor

virtual ~Array()

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<false>

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

ArrayElementRef<true>

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

Throws

None

Member Functions

getType

ArrayType getType() const

Returns

ArrayType

Array type.

Throws

None

getMemoryLayout

MemoryLayout getMemoryLayout() const

Returns

MemoryLayout

Memory layout for array, specified as MemoryLayout::COLUMN_MAJOR or MemoryLayout::ROW_MAJOR.

Throws

matlab::InvalidMemoryLayout

Invalid memory layout.

getDimensions

ArrayDimensions getDimensions() const

Returns

ArrayDimensions

Vector of each dimension in array.

Throws

None

getNumberOfElements

size_t getNumberOfElements() const

Returns

size_t

The number of elements in array.

Throws

None

isEmpty

bool isEmpty() const

Returns

bool

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

Throws

None

Free Functions

getReadOnlyElements

template <typename T>
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.

Parameters

const Array& arr

Array

Returns

Range<TypedIterator, T const>

Range containing begin and end iterators for input Array.

Throws

InvalidArrayTypeException

Array does not contain type T.

getWritableElements

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

Description

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

Parameters

Array& arr

Array

Returns

Range<TypedIterator, T>

Range containing begin and end iterators for input Array.

Throws

InvalidArrayTypeException

Array does not contain type T.

See Also

Introduced in R2017b