17
MATLAB & Simulink Working Together
While Simulink is useful for modelling and visualising processes such as feedback loops, detailed
data analysis and generation of good quality figures is still best completed within MATLAB. You can
run Simulink models and export the results to MATLAB or run Simulink models from MATLAB.
Exporting Simulink Data to MATLAB
There are multiple ways to get data from a Simulink to MATAB:
Scope Block: You can enabling data logging from a Scope block within the Configuration
Menu Logging tab (see page 9).
To Workspace block:
Once this
block is used in your model, each time you run your model
two vari-
ables are created in the MATLAB workspace:
tout
–
column vector of time steps
simout
–
variable
storing simulation data
Use a Mux if you need more than one output.
The simulation
data can be of type timeseries,
array or
structure,
as set in ‘Save Format’ in Block Parameters. Accessing your data in
MATLAB depends on the variable type you set.
After running the simulation command above, you can define the vector of time steps as:
and the columns of signal data as:
y = s.get(
‘simout’
)
if ‘Save Format’ is
array
y = s.get(
‘simout’
).Data
if ‘Save Format’ is
structure
y = s.get(
‘simout’
).signals.values
if ‘Save Format’ is
timeseries
Dostları ilə paylaş: