Using the C Math Library    

Determining Array Size

To determine the size of an array, use the mlfSize() routine. The mlfSize() routine returns a row vector containing the dimensions of the array. This code example creates a 2-by-3-by-2 array and displays the size vector returned by mlfSize().

This code produces the following output:

Length of a Single Dimension

You can also get the size of one particular dimension of an array by specifying the dimension as an input argument. To get the length of the longest dimension of a multidimensional array, use the mlfLength() routine. You can also use this routine to determine the size of a vector.

Dimension Return Values

The mlfSize() routine can optionally return each dimension in a separate array. You specify these arrays as output arguments passed to the mlfVarargout() routine. For more information about calling library routines that take variable number of input and output arguments, see Chapter 6.

The following code returns the dimensions in three output arguments: dim1, dim2, and dim3. When used with output arguments, you do not need to bind the return value from mlfSize() to a variable. The routine binds the return values to the output arguments specified. As with all bound arrays, you must explicitly free them.

If the array has more dimensions than the number of output arguments specified, the last output argument contains the product of the remaining dimensions.


 Determining Array Type Determining Array Shape