Friday, May 24, 2024
HomeMatlabUnifying MATLAB and Simulink: A Consumer Story Half 5 » Man on...

Unifying MATLAB and Simulink: A Consumer Story Half 5 » Man on Simulink

This week, I’m introducing a set of two examples applied utilizing the workflow described on this weblog publish sequence.

This week’s examples are bigger and extra advanced than the examples beforehand launched on this sequence. Hopefully, they are going to assist higher illustrate some great benefits of this workflow.


When you obtain and unzip the File Change submission, you can find the next:

workflow Undertaking

This folder accommodates a Undertaking manufactured from the core workflow recordsdata, together with the slPart class and the template library described in earlier posts. It additionally accommodates an App Designer app I developed to govern the article configuring the mannequin. This challenge is used as a referenced challenge by the 2 initiatives described within the subsequent two sections.


This script opens the instance positioned within the SimulinkExample folder. As its title implies, this instance is applied utilizing solely Simulink (no extra toolboxes). For this instance, I mixed options from the examples Automotive Suspension and mannequin sldemo_suspn_3dof, which is utilized in a number of examples, akin to A number of Simulations Workflow Suggestions.

This instance simulates the dynamics of a car suspension and could be configured to simulate a number of kinds of suspensions with totally different levels of freedom. Here’s a diagram for the 2 levels of freedom longitudinal configuration:


This script opens the instance saved within the folder SimscapeExample. I applied this instance by combining three examples from Simscape Driveline:

This instance means that you can simulate the acceleration of a car with various kinds of hybrid drivetrains.

I made a decision to incorporate this instance for a few causes. First, I discover that this workflow suits notably properly with Simscape bodily elements. Second, this illustrates that the identical workflow core functionalities, the slPart class and the system configurator app, work for various initiatives.

Every challenge accommodates a reside script (walkthroughSL.mlx or walkthrough_SSC.mlx) to information you thru the steps of use the mannequin.

Mannequin and Knowledge Hierarchy

One of many foremost takeaways from this instance is that every slPart is manufactured from a Simulink Subsystem and a MATLAB class. When assembled in a simulation, this ends in a hierarchy of MATLAB courses comparable to the hierarchy of Subsystems within the mannequin.

Whenever you open the primary mannequin within the challenge, you will note that it accommodates one Subsystem that takes as parameter an object named vehicleObject

In MATLAB, outline this variable by instantiating one of many courses within the +car package deal:

Here’s what the hierarchy of Subsystems appears like within the mannequin:

and the corresponding hierarchy of MATLAB courses:

Within the mannequin, you could find Variant Subsystems:

In MATLAB, tab-completion lists the identical obtainable variants, and you may select the energetic one by assigning it to the corresponding property of the mother or father object:

You too can tweak parameter values. For instance, the mass of the car in Simulink

could be modified in MATLAB via the car object:

See the walkthrough.mlx reside script in every challenge for extra instance MATLAB code interacting with the mannequin via the vehicleObject variable.

Configuring the Simulation Utilizing the MATLAB App

For comfort, I additionally included within the challenge a MATLAB app that I created utilizing App Designer. The app means that you can configure the MATLAB object representing the system. This app means that you can choose one slPart within the hierarchy, and edit its properties or swap with one other slPart of the identical household. Word that the vehicleObject variable within the MATLAB workspace can be up to date by the app.

To get began with app, I’m providing you with two choices, relying in your preferences:

  • Dowload and watch this 5 minutes video the place I stroll you thru how the app works
  • Use the next picture as a “cheat sheet” to get began:

Now it is your flip

Obtain the instance from MATLAB File Change, or clone the repository on GitHub and tell us what you assume within the feedback beneath. In case you just like the workflow, tell us within the feedback beneath what sort of enhancements or new options you assume MathWorks ought to present to make this workflow easier and extra strong.


Please enter your comment!
Please enter your name here

Most Popular

Recent Comments