{"id":12110,"date":"2022-04-22T13:14:52","date_gmt":"2022-04-22T17:14:52","guid":{"rendered":"https:\/\/blogs.mathworks.com\/simulink\/?p=12110"},"modified":"2022-06-14T09:29:58","modified_gmt":"2022-06-14T13:29:58","slug":"unifying-matlab-and-simulink-a-user-story-part-1","status":"publish","type":"post","link":"https:\/\/blogs.mathworks.com\/simulink\/2022\/04\/22\/unifying-matlab-and-simulink-a-user-story-part-1\/","title":{"rendered":"Unifying MATLAB and Simulink: A User Story Part 1"},"content":{"rendered":"<div class = rtcContent><div  style = 'margin: 2px 10px 9px 4px; padding: 0px; line-height: 21px; min-height: 0px; white-space: pre-wrap; color: rgb(0, 0, 0); font-family: Helvetica, Arial, sans-serif; font-style: normal; font-size: 14px; font-weight: 400; text-align: left; '><span>I recently had an interesting discussion with a group of users about modeling, simulation, and how the management of simulation data evolved at their company. What they came up with is a framework where the fundamental unit (which they call a \"Part\"), is systematically made of a Simulink <\/span><a href = \"https:\/\/www.mathworks.com\/help\/simulink\/block-masks.html\"><span>masked subsystem<\/span><\/a><span> and a <\/span><a href = \"https:\/\/www.mathworks.com\/help\/matlab\/object-oriented-programming.html\"><span>MATLAB class<\/span><\/a><span>. <\/span><\/div><div  style = 'margin: 2px 10px 9px 4px; padding: 0px; line-height: 21px; min-height: 0px; white-space: pre-wrap; color: rgb(0, 0, 0); font-family: Helvetica, Arial, sans-serif; font-style: normal; font-size: 14px; font-weight: 400; text-align: left; '><span>Why did they come up with that? To answer this question, I will quote a user from this group: \"<\/span><span style=' font-style: italic;'>What really drove MATLAB classes for us was the idea of reuse across system scales. From unit test development up to integration model<\/span><span>.\"<\/span><\/div><div  style = 'margin: 2px 10px 9px 4px; padding: 0px; line-height: 21px; min-height: 0px; white-space: pre-wrap; color: rgb(0, 0, 0); font-family: Helvetica, Arial, sans-serif; font-style: normal; font-size: 14px; font-weight: 400; text-align: left; '><span>I personally find this framework very convenient to work with, so I thought this would be an interesting story to share on this blog. With their permission, I am sharing the approach I learned from them with all of you. <\/span><\/div><div  style = 'margin: 2px 10px 9px 4px; padding: 0px; line-height: 21px; min-height: 0px; white-space: pre-wrap; color: rgb(0, 0, 0); font-family: Helvetica, Arial, sans-serif; font-style: normal; font-size: 14px; font-weight: 400; text-align: left; '><span>It's too complex to share in a single post, so I came up with a series of blog posts:<\/span><\/div><ol  style = 'margin: 10px 0px 20px; padding-left: 0px; font-family: Helvetica, Arial, sans-serif; font-size: 14px; '><li  style = 'margin-left: 56px; line-height: 21px; min-height: 0px; text-align: left; white-space: pre-wrap; '><span>Defining model data: From hardcoded values to MATLAB objects (this post)<\/span><\/li><li  style = 'margin-left: 56px; line-height: 21px; min-height: 0px; text-align: left; white-space: pre-wrap; '><span>A superclass and template subsystem as foundation of the framework<\/span><\/li><li  style = 'margin-left: 56px; line-height: 21px; min-height: 0px; text-align: left; white-space: pre-wrap; '><span>Controlling variants using MATLAB objects<\/span><\/li><li  style = 'margin-left: 56px; line-height: 21px; min-height: 0px; text-align: left; white-space: pre-wrap; '><span>Managing logging using MATLAB objects <\/span><\/li><\/ol><div  style = 'margin: 2px 10px 9px 4px; padding: 0px; line-height: 21px; min-height: 0px; white-space: pre-wrap; color: rgb(0, 0, 0); font-family: Helvetica, Arial, sans-serif; font-style: normal; font-size: 14px; font-weight: 400; text-align: left; '><span>Here are links to other posts in this series: <\/span><\/div><ul  style = 'margin: 10px 0px 20px; padding-left: 0px; font-family: Helvetica, Arial, sans-serif; font-size: 14px; '><li  style = 'margin-left: 56px; line-height: 21px; min-height: 0px; text-align: left; white-space: pre-wrap; '><a href = \"https:\/\/blogs.mathworks.com\/simulink\/2022\/04\/22\/unifying-matlab-and-simulink-a-user-story-part-1\/\"><span>Unifying MATLAB and Simulink: A User Story Part 1<\/span><\/a><span>: Parameterizing a model with MATLAB objects<\/span><\/li><li  style = 'margin-left: 56px; line-height: 21px; min-height: 0px; text-align: left; white-space: pre-wrap; '><a href = \"https:\/\/blogs.mathworks.com\/simulink\/2022\/04\/28\/unifying-matlab-and-simulink-a-user-story-part-2\/\"><span>Unifying MATLAB and Simulink: A User Story Part 2<\/span><\/a><span>: The <\/span><span style=' font-family: monospace;'>slPart<\/span><span> class, block template and data variants<\/span><\/li><li  style = 'margin-left: 56px; line-height: 21px; min-height: 0px; text-align: left; white-space: pre-wrap; '><a href = \"https:\/\/blogs.mathworks.com\/simulink\/2022\/05\/05\/unifying-matlab-and-simulink-a-user-story-part-3\/\"><span>Unifying MATLAB and Simulink: A User Story Part 3<\/span><\/a><span>: Controlling variants with MATLAB objects<\/span><\/li><li  style = 'margin-left: 56px; line-height: 21px; min-height: 0px; text-align: left; white-space: pre-wrap; '><a href = \"https:\/\/blogs.mathworks.com\/simulink\/2022\/05\/13\/unifying-matlab-and-simulink-a-user-story-part-4\/\"><span>Unifying MATLAB and Simulink: A User Story Part 4<\/span><\/a><span>: Post-processing and visualizing logged data<\/span><\/li><li  style = 'margin-left: 56px; line-height: 21px; min-height: 0px; text-align: left; white-space: pre-wrap; '><a href = \"https:\/\/blogs.mathworks.com\/simulink\/?p=12404\"><span>Unifying MATLAB and Simulink: A User Story Part 5<\/span><\/a><span>: Larger examples<\/span><\/li><\/ul><div  style = 'margin: 2px 10px 9px 4px; padding: 0px; line-height: 21px; min-height: 0px; white-space: pre-wrap; color: rgb(0, 0, 0); font-family: Helvetica, Arial, sans-serif; font-style: normal; font-size: 14px; font-weight: 400; text-align: left; '><span>I am very curious to hear in the comments below what you think about the approach described in this series of blog posts, and how differently you manage your simulation data and why.<\/span><\/div><div  style = 'margin: 2px 10px 9px 4px; padding: 0px; line-height: 21px; min-height: 0px; white-space: pre-wrap; color: rgb(0, 0, 0); font-family: Helvetica, Arial, sans-serif; font-style: normal; font-size: 14px; font-weight: 400; text-align: left; '><span>For this first post, I will cover how this group of users evolved their way of defining and specifying data for a Simulink model.<\/span><\/div><h2  style = 'margin: 20px 10px 5px 4px; padding: 0px; line-height: 20px; min-height: 0px; white-space: pre-wrap; color: rgb(33, 33, 33); font-family: Helvetica, Arial, sans-serif; font-style: normal; font-size: 20px; font-weight: 700; text-align: left; ' id = 'H_040D2329' ><span>My First Simulink Model<\/span><\/h2><div  style = 'margin: 2px 10px 9px 4px; padding: 0px; line-height: 21px; min-height: 0px; white-space: pre-wrap; color: rgb(0, 0, 0); font-family: Helvetica, Arial, sans-serif; font-style: normal; font-size: 14px; font-weight: 400; text-align: left; '><span>The first time you created a Simulink model, you very likely hardcoded numbers in block dialogs.<\/span><\/div><div  style = 'margin: 2px 10px 9px 4px; padding: 0px; line-height: 21px; min-height: 0px; white-space: pre-wrap; color: rgb(0, 0, 0); font-family: Helvetica, Arial, sans-serif; font-style: normal; font-size: 14px; font-weight: 400; text-align: left; '><span>You can find such an example model in the <\/span><a href = \"https:\/\/www.mathworks.com\/help\/releases\/R2021b\/simulink\/ug\/model-a-mechanical-system.html\"><span>first section<\/span><\/a><span> of the <\/span><a href = \"https:\/\/www.mathworks.com\/help\/releases\/R2021b\/simulink\/ug\/modeling-workflow.html\"><span>Basic Modeling Workflow<\/span><\/a><span>:<\/span><\/div><div  style = 'margin: 2px 10px 9px 4px; padding: 0px; line-height: 21px; min-height: 0px; white-space: pre-wrap; color: rgb(0, 0, 0); font-family: Helvetica, Arial, sans-serif; font-style: normal; font-size: 14px; font-weight: 400; text-align: left; '><img class = \"imageNode\" src = \"https:\/\/blogs.mathworks.com\/simulink\/files\/maskingEvolutionChapter1_1.png\" width = \"420\" height = \"203\" alt = \"\" style = \"vertical-align: baseline; width: 420px; height: 203px;\"><\/img><\/div><div  style = 'margin: 2px 10px 9px 4px; padding: 0px; line-height: 21px; min-height: 0px; white-space: pre-wrap; color: rgb(0, 0, 0); font-family: Helvetica, Arial, sans-serif; font-style: normal; font-size: 14px; font-weight: 400; text-align: left; '><span>As you can imagine, this is not a scalable solution. What if I want to simulate a model with a different set of parameters?<\/span><\/div><h2  style = 'margin: 20px 10px 5px 4px; padding: 0px; line-height: 20px; min-height: 0px; white-space: pre-wrap; color: rgb(33, 33, 33); font-family: Helvetica, Arial, sans-serif; font-style: normal; font-size: 20px; font-weight: 700; text-align: left; ' id = 'H_332A8705' ><span>MATLAB and Simulink 101: Scripts and Variables<\/span><\/h2><div  style = 'margin: 2px 10px 9px 4px; padding: 0px; line-height: 21px; min-height: 0px; white-space: pre-wrap; color: rgb(0, 0, 0); font-family: Helvetica, Arial, sans-serif; font-style: normal; font-size: 14px; font-weight: 400; text-align: left; '><span>The first natural step I see toward data management in Simulink is usually to specify variables in block dialogs, create a MATLAB script to define those variables and evaluate this script in the MATLAB base workspace.<\/span><\/div><div  style = 'margin: 2px 10px 9px 4px; padding: 0px; line-height: 21px; min-height: 0px; white-space: pre-wrap; color: rgb(0, 0, 0); font-family: Helvetica, Arial, sans-serif; font-style: normal; font-size: 14px; font-weight: 400; text-align: left; '><img class = \"imageNode\" src = \"https:\/\/blogs.mathworks.com\/simulink\/files\/maskingEvolutionChapter1_2.png\" width = \"800\" height = \"204\" alt = \"\" style = \"vertical-align: baseline; width: 800px; height: 204px;\"><\/img><\/div><div  style = 'margin: 2px 10px 9px 4px; padding: 0px; line-height: 21px; min-height: 0px; white-space: pre-wrap; color: rgb(0, 0, 0); font-family: Helvetica, Arial, sans-serif; font-style: normal; font-size: 14px; font-weight: 400; text-align: left; '><span>This has the advantage of separating the data definition from the model. For example, you could create multiple versions of the MATLAB script to define multiple datasets for the model.<\/span><\/div><div  style = 'margin: 2px 10px 9px 4px; padding: 0px; line-height: 21px; min-height: 0px; white-space: pre-wrap; color: rgb(0, 0, 0); font-family: Helvetica, Arial, sans-serif; font-style: normal; font-size: 14px; font-weight: 400; text-align: left; '><span>On the other side, this also leads to scalability issues and many potential conflicts, especially in a collaborative environment. What if someone else adds a block with a parameter also named \u201c<\/span><span style=' font-family: monospace;'>m<\/span><span>\u201d or \u201c<\/span><span style=' font-family: monospace;'>k<\/span><span>\u201d?<\/span><\/div><h2  style = 'margin: 20px 10px 5px 4px; padding: 0px; line-height: 20px; min-height: 0px; white-space: pre-wrap; color: rgb(33, 33, 33); font-family: Helvetica, Arial, sans-serif; font-style: normal; font-size: 20px; font-weight: 700; text-align: left; ' id = 'H_9620FC8F' ><span>MATLAB and Simulink 301: Functions, Structures and Masked Subsystems<\/span><\/h2><div  style = 'margin: 2px 10px 9px 4px; padding: 0px; line-height: 21px; min-height: 0px; white-space: pre-wrap; color: rgb(0, 0, 0); font-family: Helvetica, Arial, sans-serif; font-style: normal; font-size: 14px; font-weight: 400; text-align: left; '><span>The most common way to encapsulate algorithms in Simulink is through <\/span><a href = \"https:\/\/www.mathworks.com\/help\/releases\/R2022a\/simulink\/block-masks.html\"><span>masking<\/span><\/a><span>. Thanks to the mask workspace, masking provides a controlled access to the block data.<\/span><\/div><div  style = 'margin: 2px 10px 9px 4px; padding: 0px; line-height: 21px; min-height: 0px; white-space: pre-wrap; color: rgb(0, 0, 0); font-family: Helvetica, Arial, sans-serif; font-style: normal; font-size: 14px; font-weight: 400; text-align: left; '><span>In a similar way, in MATLAB, <\/span><a href = \"https:\/\/www.mathworks.com\/help\/releases\/R2022a\/matlab\/function-basics.html\"><span>functions<\/span><\/a><span> give you a workspace to encapsulate data. <\/span><\/div><div  style = 'margin: 2px 10px 9px 4px; padding: 0px; line-height: 21px; min-height: 0px; white-space: pre-wrap; color: rgb(0, 0, 0); font-family: Helvetica, Arial, sans-serif; font-style: normal; font-size: 14px; font-weight: 400; text-align: left; '><span>Combining those two concepts, the next step in this evolution is to create a MATLAB function returning a <\/span><a href = \"https:\/\/www.mathworks.com\/help\/releases\/R2022a\/matlab\/structures.html\"><span>structure<\/span><\/a><span> containing all the data needed by a masked subsystem.<\/span><\/div><div  style = 'margin: 2px 10px 9px 4px; padding: 0px; line-height: 21px; min-height: 0px; white-space: pre-wrap; color: rgb(0, 0, 0); font-family: Helvetica, Arial, sans-serif; font-style: normal; font-size: 14px; font-weight: 400; text-align: left; '><img class = \"imageNode\" src = \"https:\/\/blogs.mathworks.com\/simulink\/files\/maskingEvolutionChapter1_3.png\" width = \"701\" height = \"198\" alt = \"\" style = \"vertical-align: baseline; width: 701px; height: 198px;\"><\/img><\/div><div  style = 'margin: 2px 10px 9px 4px; padding: 0px; line-height: 21px; min-height: 0px; white-space: pre-wrap; color: rgb(0, 0, 0); font-family: Helvetica, Arial, sans-serif; font-style: normal; font-size: 14px; font-weight: 400; text-align: left; '><span>In Simulink, the algorithm is masked with a single variable, named \"data\" in this example, and the structure fields are then used in the individual blocks.<\/span><\/div><div  style = 'margin: 2px 10px 9px 4px; padding: 0px; line-height: 21px; min-height: 0px; white-space: pre-wrap; color: rgb(0, 0, 0); font-family: Helvetica, Arial, sans-serif; font-style: normal; font-size: 14px; font-weight: 400; text-align: left; '><img class = \"imageNode\" src = \"https:\/\/blogs.mathworks.com\/simulink\/files\/maskingEvolutionChapter1_4.png\" width = \"717\" height = \"549\" alt = \"\" style = \"vertical-align: baseline; width: 717px; height: 549px;\"><\/img><\/div><div  style = 'margin: 2px 10px 9px 4px; padding: 0px; line-height: 21px; min-height: 0px; white-space: pre-wrap; color: rgb(0, 0, 0); font-family: Helvetica, Arial, sans-serif; font-style: normal; font-size: 14px; font-weight: 400; text-align: left; '><span>That way, if I create a model with multiple instances of this system, I can easily create different data structures.<\/span><\/div><div  style = 'margin: 2px 10px 9px 4px; padding: 0px; line-height: 21px; min-height: 0px; white-space: pre-wrap; color: rgb(0, 0, 0); font-family: Helvetica, Arial, sans-serif; font-style: normal; font-size: 14px; font-weight: 400; text-align: left; '><img class = \"imageNode\" src = \"https:\/\/blogs.mathworks.com\/simulink\/files\/maskingEvolutionChapter1_5.png\" width = \"473\" height = \"232\" alt = \"\" style = \"vertical-align: baseline; width: 473px; height: 232px;\"><\/img><\/div><div  style = 'margin: 2px 10px 9px 4px; padding: 0px; line-height: 21px; min-height: 0px; white-space: pre-wrap; color: rgb(0, 0, 0); font-family: Helvetica, Arial, sans-serif; font-style: normal; font-size: 14px; font-weight: 400; text-align: left; '><span>and pass them to the different instances of the block.<\/span><\/div><div  style = 'margin: 2px 10px 9px 4px; padding: 0px; line-height: 21px; min-height: 0px; white-space: pre-wrap; color: rgb(0, 0, 0); font-family: Helvetica, Arial, sans-serif; font-style: normal; font-size: 14px; font-weight: 400; text-align: left; '><img class = \"imageNode\" src = \"https:\/\/blogs.mathworks.com\/simulink\/files\/maskingEvolutionChapter1_6.png\" width = \"675\" height = \"296\" alt = \"\" style = \"vertical-align: baseline; width: 675px; height: 296px;\"><\/img><\/div><h3  style = 'margin: 15px 10px 5px 4px; padding: 0px; line-height: 18px; min-height: 0px; white-space: pre-wrap; color: rgb(33, 33, 33); font-family: Helvetica, Arial, sans-serif; font-style: normal; font-size: 17px; font-weight: 700; text-align: left; ' id = 'H_380CA176' ><span>Nested Structures<\/span><\/h3><div  style = 'margin: 2px 10px 9px 4px; padding: 0px; line-height: 21px; min-height: 0px; white-space: pre-wrap; color: rgb(0, 0, 0); font-family: Helvetica, Arial, sans-serif; font-style: normal; font-size: 14px; font-weight: 400; text-align: left; '><span>One great thing with structures is that you can nest them. If you have a complex Simulink model made of multiple components and subcomponents, you can parameterize it in a similar manner, with a MATLAB structure made of sub-structures and sub-sub-structures.<\/span><\/div><div  style = 'margin: 2px 10px 9px 4px; padding: 0px; line-height: 21px; min-height: 0px; white-space: pre-wrap; color: rgb(0, 0, 0); font-family: Helvetica, Arial, sans-serif; font-style: normal; font-size: 14px; font-weight: 400; text-align: left; '><span>Let's take this model with one subsystem at the top level, <\/span><span style=' font-family: monospace;'>ComponentA<\/span><span>, is made of two subsystems, <\/span><span style=' font-family: monospace;'>My Spring 1<\/span><span> and <\/span><span style=' font-family: monospace;'>My Spring 2<\/span><span>:<\/span><\/div><div  style = 'margin: 2px 10px 9px 4px; padding: 0px; line-height: 21px; min-height: 0px; white-space: pre-wrap; color: rgb(0, 0, 0); font-family: Helvetica, Arial, sans-serif; font-style: normal; font-size: 14px; font-weight: 400; text-align: left; '><img class = \"imageNode\" src = \"https:\/\/blogs.mathworks.com\/simulink\/files\/maskingEvolutionChapter1_7.png\" width = \"804\" height = \"267\" alt = \"\" style = \"vertical-align: baseline; width: 804px; height: 267px;\"><\/img><\/div><div  style = 'margin: 2px 10px 9px 4px; padding: 0px; line-height: 21px; min-height: 0px; white-space: pre-wrap; color: rgb(0, 0, 0); font-family: Helvetica, Arial, sans-serif; font-style: normal; font-size: 14px; font-weight: 400; text-align: left; '><span>In a manner similar to the previous iteration, I can create one function for the top-level component that calls the initialization functions of two subcomponents:<\/span><\/div><div  style = 'margin: 2px 10px 9px 4px; padding: 0px; line-height: 21px; min-height: 0px; white-space: pre-wrap; color: rgb(0, 0, 0); font-family: Helvetica, Arial, sans-serif; font-style: normal; font-size: 14px; font-weight: 400; text-align: left; '><img class = \"imageNode\" src = \"https:\/\/blogs.mathworks.com\/simulink\/files\/maskingEvolutionChapter1_8.png\" width = \"605\" height = \"198\" alt = \"\" style = \"vertical-align: baseline; width: 605px; height: 198px;\"><\/img><\/div><div  style = 'margin: 2px 10px 9px 4px; padding: 0px; line-height: 21px; min-height: 0px; white-space: pre-wrap; color: rgb(0, 0, 0); font-family: Helvetica, Arial, sans-serif; font-style: normal; font-size: 14px; font-weight: 400; text-align: left; '><span>and pass that to the masked subsystem containing the two components:<\/span><\/div><div  style = 'margin: 2px 10px 9px 4px; padding: 0px; line-height: 21px; min-height: 0px; white-space: pre-wrap; color: rgb(0, 0, 0); font-family: Helvetica, Arial, sans-serif; font-style: normal; font-size: 14px; font-weight: 400; text-align: left; '><img class = \"imageNode\" src = \"https:\/\/blogs.mathworks.com\/simulink\/files\/maskingEvolutionChapter1_9.png\" width = \"746\" height = \"642\" alt = \"\" style = \"vertical-align: baseline; width: 746px; height: 642px;\"><\/img><\/div><div  style = 'margin: 2px 10px 9px 4px; padding: 0px; line-height: 21px; min-height: 0px; white-space: pre-wrap; color: rgb(0, 0, 0); font-family: Helvetica, Arial, sans-serif; font-style: normal; font-size: 14px; font-weight: 400; text-align: left; '><span>At this point there is practically no limit to the width and depth such component hierarchy can have.<\/span><\/div><div  style = 'margin: 2px 10px 9px 4px; padding: 0px; line-height: 21px; min-height: 0px; white-space: pre-wrap; color: rgb(0, 0, 0); font-family: Helvetica, Arial, sans-serif; font-style: normal; font-size: 14px; font-weight: 400; text-align: left; '><span>At the end of the day, you have a single variable in MATLAB containing a structure similar to the structure of your model.<\/span><\/div><h2  style = 'margin: 20px 10px 5px 4px; padding: 0px; line-height: 20px; min-height: 0px; white-space: pre-wrap; color: rgb(33, 33, 33); font-family: Helvetica, Arial, sans-serif; font-style: normal; font-size: 20px; font-weight: 700; text-align: left; ' id = 'H_40DB3798' ><span style=' font-weight: bold;'>MATLAB and Simulink 501: Classes and Objects<\/span><\/h2><div  style = 'margin: 2px 10px 9px 4px; padding: 0px; line-height: 21px; min-height: 0px; white-space: pre-wrap; color: rgb(0, 0, 0); font-family: Helvetica, Arial, sans-serif; font-style: normal; font-size: 14px; font-weight: 400; text-align: left; '><span>The next step in this evolution is transitioning from structures to <\/span><a href = \"https:\/\/www.mathworks.com\/help\/matlab\/object-oriented-programming.html\"><span>MATLAB classes<\/span><\/a><span>. In its simplest form, storing data in the properties of a MATLAB class is very similar to storing it in the fields of a structure.<\/span><\/div><div  style = 'margin: 2px 10px 9px 4px; padding: 0px; line-height: 21px; min-height: 0px; white-space: pre-wrap; color: rgb(0, 0, 0); font-family: Helvetica, Arial, sans-serif; font-style: normal; font-size: 14px; font-weight: 400; text-align: left; '><span>If we transition our mass-spring-damper example from a structure to a MATLAB class, here is how it would look like:<\/span><\/div><div  style = 'margin: 2px 10px 9px 4px; padding: 0px; line-height: 21px; min-height: 0px; white-space: pre-wrap; color: rgb(0, 0, 0); font-family: Helvetica, Arial, sans-serif; font-style: normal; font-size: 14px; font-weight: 400; text-align: left; '><img class = \"imageNode\" src = \"https:\/\/blogs.mathworks.com\/simulink\/files\/maskingEvolutionChapter1_10.png\" width = \"369\" height = \"329\" alt = \"\" style = \"vertical-align: baseline; width: 369px; height: 329px;\"><\/img><\/div><div  style = 'margin: 2px 10px 9px 4px; padding: 0px; line-height: 21px; min-height: 0px; white-space: pre-wrap; color: rgb(0, 0, 0); font-family: Helvetica, Arial, sans-serif; font-style: normal; font-size: 14px; font-weight: 400; text-align: left; '><span>Once the class file is created, you can instantiate it and pass the object to the mask parameter just like with a structure.<\/span><\/div><div  style = 'margin: 2px 10px 9px 4px; padding: 0px; line-height: 21px; min-height: 0px; white-space: pre-wrap; color: rgb(0, 0, 0); font-family: Helvetica, Arial, sans-serif; font-style: normal; font-size: 14px; font-weight: 400; text-align: left; '><img class = \"imageNode\" src = \"https:\/\/blogs.mathworks.com\/simulink\/files\/maskingEvolutionChapter1_11.png\" width = \"290\" height = \"205\" alt = \"\" style = \"vertical-align: baseline; width: 290px; height: 205px;\"><\/img><\/div><div  style = 'margin: 2px 10px 9px 4px; padding: 0px; line-height: 21px; min-height: 0px; white-space: pre-wrap; color: rgb(0, 0, 0); font-family: Helvetica, Arial, sans-serif; font-style: normal; font-size: 14px; font-weight: 400; text-align: left; '><img class = \"imageNode\" src = \"https:\/\/blogs.mathworks.com\/simulink\/files\/maskingEvolutionChapter1_12.png\" width = \"562\" height = \"575\" alt = \"\" style = \"vertical-align: baseline; width: 562px; height: 575px;\"><\/img><\/div><div  style = 'margin: 2px 10px 9px 4px; padding: 0px; line-height: 21px; min-height: 0px; white-space: pre-wrap; color: rgb(0, 0, 0); font-family: Helvetica, Arial, sans-serif; font-style: normal; font-size: 14px; font-weight: 400; text-align: left; '><span>In a same way as described above for structures, MATLAB objects can be nested. In that case, an object becomes the property of a parent object. As we did for the structure use case, let's create a component made of two instances of the spring as subcomponents, but with different parameter values: <\/span><\/div><div  style = 'margin: 2px 10px 9px 4px; padding: 0px; line-height: 21px; min-height: 0px; white-space: pre-wrap; color: rgb(0, 0, 0); font-family: Helvetica, Arial, sans-serif; font-style: normal; font-size: 14px; font-weight: 400; text-align: left; '><img class = \"imageNode\" src = \"https:\/\/blogs.mathworks.com\/simulink\/files\/maskingEvolutionChapter1_13.png\" width = \"383\" height = \"267\" alt = \"\" style = \"vertical-align: baseline; width: 383px; height: 267px;\"><\/img><\/div><div  style = 'margin: 2px 10px 9px 4px; padding: 0px; line-height: 21px; min-height: 0px; white-space: pre-wrap; color: rgb(0, 0, 0); font-family: Helvetica, Arial, sans-serif; font-style: normal; font-size: 14px; font-weight: 400; text-align: left; '><span>Those can then be passed as mask parameters just like structures.<\/span><\/div><div  style = 'margin: 2px 10px 9px 4px; padding: 0px; line-height: 21px; min-height: 0px; white-space: pre-wrap; color: rgb(0, 0, 0); font-family: Helvetica, Arial, sans-serif; font-style: normal; font-size: 14px; font-weight: 400; text-align: left; '><span>I will not go in details in this post, but MATLAB classes offer multiple advantages when compared to structures. In addition to declaring a formal list of properties, MATLAB classes allow you to define things like custom display and parameter validation methods. For example, you could validate that a parameter is of a specific data type or is within a certain range of values. If you want to read more on this topic I encourage you to see this blog post by <\/span><a href = \"https:\/\/www.mathworks.com\/matlabcentral\/profile\/authors\/8026264\"><span>Tim Johns<\/span><\/a><span> on the <\/span><a href = \"https:\/\/blogs.mathworks.com\/developer\/\"><span>Developer zone<\/span><\/a><span> blog: <\/span><a href = \"https:\/\/blogs.mathworks.com\/developer\/2022\/03\/17\/using-custom-classes-to-convey-intent\/\"><span>You\u2019ve Got Mail<\/span><\/a><\/div><h2  style = 'margin: 20px 10px 5px 4px; padding: 0px; line-height: 20px; min-height: 0px; white-space: pre-wrap; color: rgb(33, 33, 33); font-family: Helvetica, Arial, sans-serif; font-style: normal; font-size: 20px; font-weight: 700; text-align: left; ' id = 'H_A2B9E33D' ><span>Now it's your turn<\/span><\/h2><div  style = 'margin: 2px 10px 9px 4px; padding: 0px; line-height: 21px; min-height: 0px; white-space: pre-wrap; color: rgb(0, 0, 0); font-family: Helvetica, Arial, sans-serif; font-style: normal; font-size: 14px; font-weight: 400; text-align: left; '><span>I will stop here for this first post. In my next post, I will dive into the advantages and possibilities that MATLAB objects enable in this context.<\/span><\/div><div  style = 'margin: 2px 10px 9px 4px; padding: 0px; line-height: 21px; min-height: 0px; white-space: pre-wrap; color: rgb(0, 0, 0); font-family: Helvetica, Arial, sans-serif; font-style: normal; font-size: 14px; font-weight: 400; text-align: left; '><span>I have seen multiple users leveraging MATLAB structures and objects to parameterize Simulink models. If this is your case, I would be very interested to hear in the comments below what lead you to this solution, and what are the advantages\/inconvenient you are seeing with this technique.<\/span><\/div>\r\n<\/div><script type=\"text\/javascript\">var css = ''; var head = document.head || document.getElementsByTagName('head')[0], style = document.createElement('style'); head.appendChild(style); style.type = 'text\/css'; if (style.styleSheet){ style.styleSheet.cssText = css; } else { style.appendChild(document.createTextNode(css)); }<\/script><a href=\"https:\/\/blogs.mathworks.com\/simulink\/files\/maskingEvolutionChapter1.mlx\"><button class=\"btn btn-sm btn_color_blue pull-right add_margin_10\">Download Live Script<\/button><\/a>","protected":false},"excerpt":{"rendered":"<div class=\"overview-image\"><img src=\"https:\/\/blogs.mathworks.com\/simulink\/files\/ml_sl.png\" class=\"img-responsive attachment-post-thumbnail size-post-thumbnail wp-post-image\" alt=\"\" decoding=\"async\" loading=\"lazy\" \/><\/div><p>I recently had an interesting discussion with a group of users about modeling, simulation, and how the management of simulation data evolved at their company. What they came up with is a framework... <a class=\"read-more\" href=\"https:\/\/blogs.mathworks.com\/simulink\/2022\/04\/22\/unifying-matlab-and-simulink-a-user-story-part-1\/\">read more >><\/a><\/p>","protected":false},"author":41,"featured_media":12116,"comment_status":"open","ping_status":"closed","sticky":false,"template":"","format":"standard","meta":[],"categories":[34,47,30,69],"tags":[638],"_links":{"self":[{"href":"https:\/\/blogs.mathworks.com\/simulink\/wp-json\/wp\/v2\/posts\/12110"}],"collection":[{"href":"https:\/\/blogs.mathworks.com\/simulink\/wp-json\/wp\/v2\/posts"}],"about":[{"href":"https:\/\/blogs.mathworks.com\/simulink\/wp-json\/wp\/v2\/types\/post"}],"author":[{"embeddable":true,"href":"https:\/\/blogs.mathworks.com\/simulink\/wp-json\/wp\/v2\/users\/41"}],"replies":[{"embeddable":true,"href":"https:\/\/blogs.mathworks.com\/simulink\/wp-json\/wp\/v2\/comments?post=12110"}],"version-history":[{"count":2,"href":"https:\/\/blogs.mathworks.com\/simulink\/wp-json\/wp\/v2\/posts\/12110\/revisions"}],"predecessor-version":[{"id":12542,"href":"https:\/\/blogs.mathworks.com\/simulink\/wp-json\/wp\/v2\/posts\/12110\/revisions\/12542"}],"wp:featuredmedia":[{"embeddable":true,"href":"https:\/\/blogs.mathworks.com\/simulink\/wp-json\/wp\/v2\/media\/12116"}],"wp:attachment":[{"href":"https:\/\/blogs.mathworks.com\/simulink\/wp-json\/wp\/v2\/media?parent=12110"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"https:\/\/blogs.mathworks.com\/simulink\/wp-json\/wp\/v2\/categories?post=12110"},{"taxonomy":"post_tag","embeddable":true,"href":"https:\/\/blogs.mathworks.com\/simulink\/wp-json\/wp\/v2\/tags?post=12110"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}