Main Content

Query Array Size and Characteristics

This example shows how to query the size of model arrays, including the number of inputs and outputs of the models in the array, and the array dimensions. It also shows how to query characteristics of the models in the array, such as stability.

Array Size

Model arrays have two different sets of dimensions, the I/O dimensions and the array dimensions. The I/O dimensions are the numbers of inputs and outputs of the models in the array. (Each model in an array must have the same I/O dimensions.) The array dimensions are the dimensions of the array itself. Load a saved model array and query its dimensions.

2x4 array of state-space models.
Each model has 3 outputs, 1 inputs, and 3 states.

When you use the size command on a model array with no output argument, the display shows the two sets of dimensions.

To obtain the array dimensions as a numeric array, use size with an output argument.

dims = size(sysarr)
dims = 1×4

     3     1     2     4

The first two entries in dims are the I/O dimensions of the models in sysarr, which each have three outputs and one input. The remaining entries in dims are the dimensions of the array itself. Thus, sysarr is a 2-by-4 array of models.

To query the number of dimensions in the array, rather than the values of those dimensions, use ndims.

dims = ndims(sysarr)
dims = 4

In this case, sysarr has 4 = 2 + 2 dimensions: The I/O dimensions (outputs and inputs), and the array dimensions. Query the I/O dimensions alone using the iosize command.

ios = iosize(sysarr)
ios = 1×2

     3     1

Query the total number of models in the array.

N = nmodels(sysarr)
N = 8

Because sysarr is a 2-by-4 array of models, this command returns a value of 2 × 4 = 8.

Characteristics of Models in the Array

Query commands such as isproper and isstable work on model arrays. For example, query whether the models in sysarr are stable.

Bsiso = isstable(sysarr)
Bsiso = logical

By default, isstable returns 1 (true) if all of the models in the array are stable. The commands returns 0 (false) if one or more of the models is not stable. To perform an element-by-element query of a model array, use the 'elem' option.

Bsiso = isstable(sysarr,'elem')
Bsiso = 2x4 logical array

   1   1   1   1
   1   1   1   1

Now isstable returns an array of Boolean values. The dimensions of this array match the array dimensions of sysarr. Each entry in the array Bsiso indicates whether the corresponding model of sysarr is stable. The 'elem' option works similarly for many query commands.

Related Topics