This example shows how you can log and plot simulation data instead of adding sensors to your model.
The model shown represents a permanent magnet DC motor.
This model is very similar to the Permanent Magnet DC Motor example, but, unlike the example model, it does not include the Ideal Rotational Motion Sensor and the Current Sensor blocks, along with the respective PS-Simulink Converter blocks and scopes. For a detailed description of the Permanent Magnet DC Motor example, see Evaluating Performance of a DC Motor.
Build the model, as shown in the preceding illustration.
To enable data logging, open the Configuration Parameters
dialog box, in the left pane, select Simscape,
then set the Log simulation data parameter to
Simulate the model. This creates a workspace variable
simlog (as specified by the Workspace
variable name parameter), which contains the simulation
simlog variable has the same
hierarchy as the model. To see the whole variable structure, at the
command prompt, type:
This command prints the whole data tree.
mlog_ex_dcmotor1 +-Electrical_Reference2 | +-V | | +-v | +-i +-Friction_Mr | +-C | | +-w | +-R | | +-w | +-t | +-w +-L | +-i | +-i_L | +-n | | +-v | +-p | | +-v | +-v +-Load_Torque | +-C | | +-w | +-R | | +-w | +-S | +-t | +-w +-Mechanical_Rotational_Reference | +-W | | +-w | +-t +-Mechanical_Rotational_Reference1 | +-W | | +-w | +-t +-Motor_Inertia_J | +-I | | +-w | +-t +-Rotational_Electromechanical_Converter | +-C | | +-w | +-R | | +-w | +-i | +-n | | +-v | +-p | | +-v | +-t | +-v | +-w +-Rotor_Resistance_R | +-i | +-n | | +-v | +-p | | +-v | +-v +-Simulink_PS_Converter +-x1_5V +-i +-n | +-v +-p | +-v +-v
Every node that represents an Across, Through, or internal block variable contains series data. To get to the series, you have to specify the complete path to it through the tree, starting with the top-level variable name. For example, to get a handle on the series representing the angular velocity of the motor, type:
s1 = simlog.Rotational_Electromechanical_Converter.R.w.series;
From here, you can access the values and time vectors for the series and analyze them.
You do not have to isolate series data to plot its values against time, or against another series. For example, to see how the motor speed (in revolutions per minute) changes with time, type:
Compare this figure to the RPM scope display in the Permanent Magnet DC Motor example. The results are exactly the same.
To plot the motor torque against its angular velocity,
rpm, and add descriptive axis names, type:
plotxy(simlog.Rotational_Electromechanical_Converter.R.w,simlog.Motor_Inertia_J.t,... 'xunit','rpm','xname','Angular velocity','yname','Torque')