Exporting to the MATLAB Workspace Matlab Help

Exporting to the MATLAB Workspace

We now demonstrate how to export the results of the simulation to the MATLAB work-space, where they can be plotted or analyzed with any of the MATLAB functions .
Solution
Modify the Simulink model constructed in Example 9.2-1 as follows. Refer
Figure 9.2-3.

1. Delete the arrow connecting the Scope block by clicking on it and pressing the Delete key. Delete the Scope block in the same way.
2. Select and place the To Work-space block from the Sinks library and the Clock bl from the Sources library.
3. Select and place the Mux block from the Signal Routing library, double-click on it, and set the Number of inputs to 2. Click OK. (The name Mux is an

Simulink model using the Clock and To Workspaceblocks.

Simulink model using the Clock and To
Workspaceblocks.

abbreviation for multiplexer, which is an electrical device for transmitting several signals.)
4. Connect the top input port of the Mux block to the output port of the Integrator block. Then use the same technique to connect the bottom input port of the Mux block to the output port of the Clock block. Your model should now look like that shown in Figure 9.2-3.
5. Double-click on the To Work-space block. You can specify any variable name you want as the output; the default is simout. Change its name to y. The output variable y will have as many rows as there are simulation time steps, and as many columns as there are inputs to the block. The second column in our simulation will
be time, because of the way we have connected the Clock to the second input port of the Mux. Specify the Save format as Array. Use the default values for the other parameters (these should be inf, 1,and -1 for Maximum number of rows, Decimation, and Sample time, respectively). Click on OK.
6. After running the simulation, you can use the MATLAB plotting commands from the Command window to plot the columns ofy (or simout in general). To plot y(t), type in the MATLAB Command window:
»plot (y(: ,2) ,y(:, 1)) ,xlabel (‘t’) ,ylabel (‘y’)

 

Posted on July 30, 2015 in simulink

Share the Story

Back to Top
Share This