arrayalloc

Purpose

Creates an N-dimensional array with unspecified contents.

Format

y = arrayalloc(orders, cf)
Parameters:
  • orders (Nx1 vector of orders) – the sizes of the dimensions of the array.

  • cf (scalar) – 0 to allocate real array, or 1 to allocate complex array.

Returns:

y (N-dimensional array) –

Examples

orders = { 2, 3, 4 };
y = arrayalloc(orders, 1);

y will be a complex 2x3x4 array with unspecified contents.

// Set orders to create a 7x5x3 dimensional array
orders = { 7, 5, 3 };

// Create a real 7x5x3 dimensional array
y = arrayalloc(orders, 0);

Remarks

The contents are unspecified. To create a new array with all elements initialized to a particular scalar value, use arrayinit().

arrayalloc() is used to allocate an array that will be written to in sections using setarray, or indexed assignments. It is much faster to preallocate an array and fill in sections during a loop rather than adding new sections with concatentaion.

See also

Functions arrayinit(), setarray