You can read fixed-point data from the MATLAB® software into your Simulink® models, and there are a number of ways in which you can log fixed-point information from your models and simulations to the workspace.
Use the From Workspace block
to read fixed-point data from the MATLAB workspace into a Simulink model.
To do this, the data must be in structure format with a Fixed-Point
values field. In array format, the From
Workspace block only accepts real, double-precision data.
To read in
fi data, the Interpolate
data parameter of the From Workspace block must not be
selected, and the Form output after final data value by parameter
must be set to anything other than
You can write fixed-point output from a model to the MATLAB workspace via the To Workspace block in either array or structure format. Fixed-point data written by a To Workspace block to the workspace in structure format can be read back into a Simulink model in structure format by a From Workspace block.
To write fixed-point data to the workspace as a
select the Log fixed-point data as a fi object check
box on the To Workspace block dialog. Otherwise, fixed-point data
is converted to
double and written to the workspace
For example, you can use the following code to create a structure
in the MATLAB workspace with a
fi object in
values field. You can then use the From Workspace
block to bring the data into a Simulink model.
a = fi([sin(0:10)' sin(10:-1:0)']) a = 0 -0.5440 0.8415 0.4121 0.9093 0.9893 0.1411 0.6570 -0.7568 -0.2794 -0.9589 -0.9589 -0.2794 -0.7568 0.6570 0.1411 0.9893 0.9093 0.4121 0.8415 -0.5440 0 DataTypeMode: Fixed-point: binary point scaling Signedness: Signed WordLength: 16 FractionLength: 15 s.signals.values = a s = signals: [1x1 struct] s.signals.dimensions = 2 s = signals: [1x1 struct] s.time = [0:10]' s = signals: [1x1 struct] time: [11x1 double]
The From Workspace block in the following model has the
the Data parameter. In the model, the following
parameters in the Solver pane of the Configuration
Parameters dialog box have the indicated settings:
Start time —
Stop time —
(no continuous states)
Fixed-step size (fundamental sample time) —
The To Workspace block writes the result of the simulation to
the MATLAB workspace as a
simout.signals.values ans = 0 -8.7041 13.4634 6.5938 14.5488 15.8296 2.2578 10.5117 -12.1089 -4.4707 -15.3428 -15.3428 -4.4707 -12.1089 10.5117 2.2578 15.8296 14.5488 6.5938 13.4634 -8.7041 0
When fixed-point signals are logged to the MATLAB workspace
via signal logging, they are always logged as Fixed-Point
To enable signal logging for a signal:
Select the signal.
Click the Simulation Data Inspector button arrow.
Select Log Selected Signals.
For more information, refer to Signal Logging (Simulink).
When you log signals from a referenced model or Stateflow® chart
in your model, the word lengths of
fi objects may
be larger than you expect. The word lengths of fixed-point signals
in referenced models and Stateflow charts are logged as the next
larger data storage container size.
Simulink provides an application programming interface
(API) that enables programmatic access to block data, such as block
inputs and outputs, parameters, states, and work vectors, while a
simulation is running. You can use this interface to develop MATLAB programs
capable of accessing block data while a simulation is running or to
access the data from the MATLAB command line. Fixed-point signal
information is returned to you via this API as
For more information about the API, refer to Access Block Data During Simulation (Simulink).