Using Simulink Previous page   Next Page

Exporting Output Data to the MATLAB Workspace

You can specify return variables by selecting the Time, States, and/or Output check boxes in the Save to workspace area of this dialog box pane. Specifying return variables causes Simulink to write values for the time, state, and output trajectories (as many as are selected) into the workspace.

To assign values to different variables, specify those variable names in the fields to the right of the check boxes. To write output to more than one variable, specify the variable names in a comma-separated list. Simulink saves the simulation times in the vector specified in the Save to workspace area.

The Save options area enables you to specify the format and restrict the amount of output saved.

Format options for model states and outputs are listed below.

Array.   If you select this option, Simulink saves a model's states and outputs in a state and output array, respectively.

The state matrix has the name specified in the Save to workspace area (for example, xout). Each row of the state matrix corresponds to a time sample of the model's states. Each column corresponds to an element of a state. For example, suppose that your model has two continuous states, each of which is a two-element vector. Then the first two elements of each row of the state matrix contains a time sample of the first state vector. The last two elements of each row contain a time sample of the second state vector.

The model output matrix has the name specified in the Save to workspace area (for example, yout). Each column corresponds to a model outport, each row to the outputs at a specific time.

Structure with time.   If you select this format, Simulink saves the model's states and outputs in structures having the names specified in the Save to workspace area (for example, xout and yout).

The structure used to save outputs has two top-level fields: time and signals. The time field contains a vector of the simulation times. The signals field contains an array of substructures, each of which corresponds to a model outport. Each substructure has four fields: values, dimensions, label, and blockName. The values field contains the outputs for the corresponding outport. If the outputs are scalars or vectors, the values field is a matrix each of whose rows represents an output at the time specified by the corresponding element of the time vector. If the outputs are matrix (2-D) values, the values field is a 3-D array of dimensions M-by-N-by-T where M-by-N is the dimensions of the output signal and T is the number of output samples. If T = 1, MATLAB drops the last dimension. Therefore, the values field is an M-by-N matrix. The dimensions field specifies the dimensions of the output signal. The label field specifies the label of the signal connected to the outport or the type of state (continuous or discrete). The blockName field specifies the name of the corresponding outport or block with states.

The structure used to save states has a similar organization. The states structure has two top-level fields: time and signals. The time field contains a vector of the simulation times. The signals field contains an array of substructures, each of which corresponds to one of the model's states. Each signals structure has four fields: values, dimensions, label, and blockName. The values field contains time samples of a state of the block specified by the blockName field. The label field for built-in blocks indicates the type of state: either CSTATE (continuous state) or DSTATE (discrete state). For S-Function blocks, the label contains whatever name is assigned to the state by the S-Function block.

The time samples of a state are stored in the values field as a matrix of values. Each row corresponds to a time sample. Each element of a row corresponds to an element of the state. If the state is a matrix, the matrix is stored in the values array in column-major order. For example, suppose that the model includes a 2-by-2 matrix state and that Simulink logs 51 samples of the state during a simulation run. The values field for this state would contain a 51-by-4 matrix where each row corresponds to a time sample of the state and where the first two elements of each row correspond to the first column of the sample and the last two elements correspond to the second column of the sample.

Simulink can read back simulation data saved to the workspace in the Structure with time output format. See Importing signal-and-time data structures for more information.

Structure.   This format is the same as the preceding except that Simulink does not store simulation times in the time field of the saved structure.

Per-Port Structures.   This format consists of a separate structure-with-time or structure-without-time for each output port. Each output data structure has only one signals field. To specify this option, enter the names of the structures in the Output text field as a comma-separated list, out1, out2,..., outN, where out1 is the data for your model's first port, out2 for the second inport, and so on.


Previous page  Importing and Exporting Simulation Data Importing and Exporting States Next page

© 1994-2005 The MathWorks, Inc.