Thursday, April 25, 2024
HomeMatlabUnifying MATLAB and Simulink: A Person Story Half 1 » Man on...

Unifying MATLAB and Simulink: A Person Story Half 1 » Man on Simulink


I just lately had an attention-grabbing dialogue with a bunch of customers about modeling, simulation, and the way the administration of simulation knowledge advanced at their firm. What they got here up with is a framework the place the elemental unit (which they name a “Half”), is systematically fabricated from a Simulink masked subsystem and a MATLAB class.

Why did they provide you with that? To reply this query, I’ll quote a consumer from this group: “What actually drove MATLAB courses for us was the thought of reuse throughout system scales. From unit check improvement as much as integration mannequin.”

I personally discover this framework very handy to work with, so I assumed this might be an attention-grabbing story to share on this weblog. With their permission, I’m sharing the strategy I discovered from them with all of you.

It is too complicated to share in a single put up, so I got here up with a collection of weblog posts:

  1. Defining mannequin knowledge: From hardcoded values to MATLAB objects (this put up)
  2. A superclass and template subsystem as basis of the framework
  3. Controlling variants utilizing MATLAB objects
  4. Managing logging utilizing MATLAB objects

Listed below are hyperlinks to different posts on this collection:

I’m very curious to listen to within the feedback under what you concentrate on the strategy described on this collection of weblog posts, and the way in a different way you handle your simulation knowledge and why.

For this primary put up, I’ll cowl how this group of customers advanced their manner of defining and specifying knowledge for a Simulink mannequin.

My First Simulink Mannequin

The primary time you created a Simulink mannequin, you very probably hardcoded numbers in block dialogs.

As you’ll be able to think about, this isn’t a scalable resolution. What if I wish to simulate a mannequin with a distinct set of parameters?

MATLAB and Simulink 101: Scripts and Variables

The primary pure step I see towards knowledge administration in Simulink is normally to specify variables in block dialogs, create a MATLAB script to outline these variables and consider this script within the MATLAB base workspace.

This has the benefit of separating the information definition from the mannequin. For instance, you could possibly create a number of variations of the MATLAB script to outline a number of datasets for the mannequin.

On the opposite facet, this additionally results in scalability points and plenty of potential conflicts, particularly in a collaborative setting. What if another person provides a block with a parameter additionally named “m” or “ok”?

MATLAB and Simulink 301: Capabilities, Buildings and Masked Subsystems

The commonest technique to encapsulate algorithms in Simulink is thru masking. Because of the masks workspace, masking offers a managed entry to the block knowledge.
In an identical manner, in MATLAB, capabilities offer you a workspace to encapsulate knowledge.
Combining these two ideas, the subsequent step on this evolution is to create a MATLAB perform returning a construction containing all the information wanted by a masked subsystem.

In Simulink, the algorithm is masked with a single variable, named “knowledge” on this instance, and the construction fields are then used within the particular person blocks.

That manner, if I create a mannequin with a number of cases of this method, I can simply create totally different knowledge constructions.

and cross them to the totally different cases of the block.

Nested Buildings

One good thing with constructions is which you could nest them. You probably have a fancy Simulink mannequin fabricated from a number of elements and subcomponents, you’ll be able to parameterize it in an identical method, with a MATLAB construction fabricated from sub-structures and sub-sub-structures.

Let’s take this mannequin with one subsystem on the high degree, ComponentA, is fabricated from two subsystems, My Spring 1 and My Spring 2:

In a way just like the earlier iteration, I can create one perform for the top-level part that calls the initialization capabilities of two subcomponents:

and cross that to the masked subsystem containing the 2 elements:

At this level there’s virtually no restrict to the width and depth such part hierarchy can have.

On the finish of the day, you may have a single variable in MATLAB containing a construction just like the construction of your mannequin.

MATLAB and Simulink 501: Courses and Objects

The subsequent step on this evolution is transitioning from constructions to MATLAB courses. In its easiest kind, storing knowledge within the properties of a MATLAB class is similar to storing it within the fields of a construction.

If we transition our mass-spring-damper instance from a construction to a MATLAB class, right here is how it will appear to be:

As soon as the category file is created, you’ll be able to instantiate it and cross the thing to the masks parameter identical to with a construction.

In a similar manner as described above for constructions, MATLAB objects might be nested. In that case, an object turns into the property of a mum or dad object. As we did for the construction use case, let’s create a part fabricated from two cases of the spring as subcomponents, however with totally different parameter values:

These can then be handed as masks parameters identical to constructions.

I can’t go in particulars on this put up, however MATLAB courses supply a number of benefits when in comparison with constructions. Along with declaring a proper checklist of properties, MATLAB courses will let you outline issues like customized show and parameter validation strategies. For instance, you could possibly validate {that a} parameter is of a particular knowledge kind or is inside a sure vary of values. If you wish to learn extra on this matter I encourage you to see this weblog put up by Tim Johns on the Developer zone weblog: You’ve Received Mail

Now it is your flip

I’ll cease right here for this primary put up. In my subsequent put up, I’ll dive into the benefits and prospects that MATLAB objects allow on this context.

I’ve seen a number of customers leveraging MATLAB constructions and objects to parameterize Simulink fashions. If that is your case, I might be very to listen to within the feedback under what lead you to this resolution, and what are the benefits/inconvenient you might be seeing with this system.

RELATED ARTICLES

LEAVE A REPLY

Please enter your comment!
Please enter your name here

Most Popular

Recent Comments