Question 5.4.2: Exporting to the MATLAB Workspace We now demonstrate how to ...

Exporting to the MATLAB Workspace

We now demonstrate how to export the results of the simulation to the MATLAB workspace, where they can be plotted or analyzed with any of the MATLAB functions.

Modify the Simulink model constructed in Example 5.4.1 as follows. Refer to Figure 5.4.5.
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 Workspace block from the Sinks category and the Clock block from the Sources category.
3. Select and place the Mux block from the Signal Routing category, double-click on it, and set the Number of inputs to 2. Click OK. (The name “Mux” is an 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 outport port of the Clock block. Your model should now look like that shown in Figure 5.4.5.
5. Double-click on the To Workspace 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 of y (or simout in general). To plot y(t), type in the MATLAB Command window:

>>plot(y(:,2),y(:,1)),xlabel('t'),ylabel('y')

5.4.5

Related Answered Questions