15 Simulink Features You Need Now
Overview
Are you getting the most out of Simulink, or are you still using it just the way you first learned it? With over 2,000 people working year-round to design, build, test, and document MathWorks products, it is a safe bet that there are more than a few useful features that you don't know about. Some features will be very new, while others may have been around for a few releases. How many of them will be new to you?
About the Presenter
Ed Marquez is a Simulink Product Manager at MathWorks. He supports automated report generation and Model-Based Design applications. Ed is experienced in automotive system modeling and controls. He holds a MS and BS in Mechanical Engineering from Virginia Tech.
Recorded: 24 Mar 2022
Hi, everyone. Welcome to this session on 15 Simulink features you need now. You probably started using MATLAB and Simulink five, 10, or 15 years ago, or maybe even longer than that, and a lot has changed in that time. So a question for today's session is, are you still using Simulink in the same way you first learned it? Or are you keeping up with new capabilities that help you get the most out of Simulink to get your work done? Hopefully today's session will help you with the latter.
My name is Ed Marquez. I'm a product marketing manager at MathWorks and I've been here for the past five years. My work is focused on Simulink and also model-based design. Before MathWorks I had the opportunity to apply model-based design in the automotive industry. In case you need a refresher or maybe your new to MathWorks tools, Simulink is a platform for model-based design. And that means that models are at the center of the development process.
This can be from requirements capture all the way to the operation of the system that you're building. Or you can use models at any stage of your development for things like modeling and simulation, testing and verification, and automatic code generation. Today I'm going to cover capabilities that help you focus on your work, capabilities that help you collaborate with others, and then I'll close with some resources for upgrading and for staying up to date.
I'm going to cover most topics with examples, and you will have access to these examples. They're all included in the product or in File Exchange in MATLAB central. And the goal with the examples is to show you how the features work, but also to give you a starting point for you to be able to use these capabilities in your own projects. And then I also have this checklist model that I'll use as a tracker as we cover our features today. So let's start with model editing.
In the past, you had to have the library browser open and you had to drag and drop components into your model. And the issue with that was the context switching. It felt like the tool was in the way of your thought process. So we improve that with predictive quick inserts. So now you can just type in the canvas and you get suggestions, and you can insert blocks and model elements, or find actions in that way.
So now it's much easier and faster to sketch out a model. You start by just drawing in the canvas. You can also size and snap to other objects that are already there. You make connections quickly. You can also rename ports as you create them. And you add connections anywhere. And it's pretty easy to have models that are clean, readable, and also well-documented. For example, it's easy to add information to your model by just dragging and dropping information or copy-pasting that information in the canvas.
And Simulink helps you resize blocks to show ports and parameters more clearly. Also if you work with the keyboard, there are improvements there too. So you can move around your model with the arrow keys, and you can also toggle to select one or more elements and change the placement for those blocks. And you can also edit the text on model elements with F2, so you can easily rename blocks that way and that also works with all of our editors including Stateflow.
Speaking of Stateflow, there are improvements for editing state charts and decision logic. To show you those I'm going to use this model of a dual-clutch transmission. So if we go into the transmission controller, here we go into the shift state, there is a Stateflow chart. So if we focus on the bottom section of this state chart, the first thing you'll see is that we can now use Quick Insert just like we can in Simulink to introduce elements into our chart. You also get smart edit guides that help you align elements in the canvas.
And another improvement is that it's really simple to reverse the transitions in your logic. So for example if I take this transition here, it takes just one click for me to reverse that transition, and I can do that with this one here as well. So something that used to take three clicks at least now takes one click. And you can also undo that with Control-Z, as I'm doing right here. Another improvement is the transition label stamps that help you avoid confusion where maybe your conditions are placed too far away from the right conditions. So now you can avoid that confusion because you can tell which condition is associated with what transition.
And finally last but not least, Stateflow also lets you customize the syntax highlighting for your data now. So when you enable that under the Format options in the tool strip and the Style button, you can customize the colors for specific types of data. So for example here, I can change the color for local data. And when I apply that you see the change, but you can also turn it on and turn it off as well to focus on the type of data that you're most interested in.
Finally, I also want to talk about the tool strip because the tool strip is a major improvement for how Simulink presents you capabilities that help you do your work. A nice thing about the tool strip is that it presents to you features and menus based on the work that you're doing and the elements that you select. In addition to that, the menus in the tool strip are organized by workflow, so you get a tab for simulation, for debugging, modeling, one for format, and also one for apps.
And these apps are user interfaces that have their own workflow, and so they make it easier for you to accomplish specific tasks. For example, things like an automatic co-generation from your models and a lot more. So those are the enhancements that I wanted to cover for model editing, so now we can check that off our list from our checklist model. And now I want to talk to you about capabilities for speeding up simulations. And one great way to do that is by running large simulation jobs in parallel. The example that I'm using is in this documentation link that you see here at the bottom of the screen.
And in this example, we're running parallel simulations while changing two variables. We're going to change the cross-sectional area of a tank, that's a, and the height of the tank, that's h. And the goal is to determine the total cost in dollars of producing a tank full of product. Again in very generic terms, we're varying the area and height of a tank to determine a dollar cost. I've already configured my parsing script to vary a and h between 0 and 5, and I'm running 750 simulations with 20 workers.
If we look at the script I used to set up the simulations, the first section opens the Simulink model, it specifies the range of values we want to try for the variables a and h, and it randomize the 750 samples. So we run that. The next section defines the simulation input object we want to use with our model and it specifies the PostSim function that I'm using to calculate the cost in our problem. So we run that too.
And then the last section passes the different values for our variables, it also creates the parallel pool of 20 workers, and it runs the simulation in parallel with the parsing command. Here I'm using the Simulation Manager to monitor and analyze the simulations as they happen. And FastRestart helps me speed up things because the model only compiles once and then it's ready to go for all the next iterations. Here the Simulation Manager window comes up and it helps you monitor progress for multiple simulations and visualize the results as the job is running.
If we look at Figure 1, we see a scatter showing the simulation status for combinations of a and h. So this can tell us right away what ranges calls the simulations to error out because we would see red dots in the scatter plot. We can also add as many figures as we need. I'm actually going to add a surface plot. And here I want to see the relationship between our variables and the cost. So I make those changes in the plot properties, and I get an idea of what their relationship looks like.
And I can also add a color bar to estimate values. I can also visualize the same data as a scatter plot in 2D. So I'll add another figure, and I'm going to configure the axis with the right variables. And now I can customize the layout of how all this information is presented to us. And we can even select data points in plots for specific regions of interest. So there you have it, this massive simulation workflow is valuable with these analysis capabilities that have been added recently. So the goal here is to help you save time as you explore the design space and run large simulations.
Another great capability for speeding up simulations is the Performance Advisor. So if we open up the model that we just simulated in parallel or any other model, we can get to the Performance Advisor from the Debug tab in the Simulink tool strip. So here is the Performance Advisor. And this advisor runs checks and gives you suggestions on changes you can make or configuration parameters you can modify to speed up the execution of your models. And there are a lot of checks, so I encourage you to check it out on your end, give it a try today.
And it also points you to other advisors for things like upgrading or generating code. You can always learn more in our documentation for this advisor, and there are also dedicated videos on how to use it with specific examples. So be sure to check those out, but I just wanted to make you aware that this is also available for you. So that is it for performance, and we can check that in our checklist.
And we can move on to the next topic, which is modeling runtime software. For this area of software modeling I want to take a step back and mention that Simulink helps you model from the component level to the system level. And that's true for software and for physical systems. And a tool that can handle all that is key as you are tasked with building more complex systems that include software, multiple components, different domains, and so on.
If you're working on systems with distributed architectures, perhaps you're integrating software components using middleware, well, components in those software compositions generate events and data asynchronously, so it can be a challenge to model that message-based communication and also to generate code from that. So to make that challenge easier we introduced a new library, and that library is called Messages and Events. That's part of Simulink now. And messages are useful because they combine events with data, and so this library gives you blocks for sending, receiving, and queuing messages. And there are other blocks, like the Sequence Viewer, that allow you to visualize all event activity in a model.
Before this library, just to give you some context, Stateflow and SimEvents were the main ways to work with messages in Simulink. But now you can tackle more complex use cases with all these tools. And SimEvents gives you a great way to handle things like message routing and delay between components. And with Stateflow you can do the state management, logic, and the handshaking. There are examples available with this new library to help you get started, and here are a couple of those you can check out in the product today.
All right, so we saw that messages give you a new way to model software components, and they also simplify the integration of those software components. Now let's talk about visualization and control. And in the Messages library there is also a Sequence Viewer block that I mentioned before. And the goal with this block is to help you visualize the messages and the events in your model.
And in fact you see it here, what you see in the y-axis looking down is time. And then on the x-axis are the different components. And the data that you see are the events that happen and the data that is contained by those events or those messages. So that is one way or one tool that helps you visualize event activity in your model.
Another new tool that you have for modeling runtime software is the Schedule Editor. And this feature helps you control the execution of components in your models. And using it you can also manage that scheduling process visually. And what you see here are partitions of a model and you can control the execution order of those partitions interactively. And this works for both export function models and rate-based models. And if you're already doing scheduling with Stateflow, then the Schedule Editor also allows you to schedule execution based on events from Stateflow. So those are the new capabilities that I wanted to cover for modeling runtime software.
Then moving on, let's talk about analyzing simulations. Simulink has also been getting updates and new ways to visualize simulation data. And one of those new ways is with the Record block. So this block shows you the data, gives you some simulation controls for you to run simulations. And as the model runs, you can actually visualize the data that it's generating.
This block also gives you a convenient replacement for the To Workspace and To File blocks. And one advantage is that you can actually log data to both locations from the same interface. And the Record block also supports the same visualizations types that are supported by the Simulation Data Inspector, like sparklines, time plots, maps, xy plots, and more. And in fact when you want to do more in-depth analysis or further analysis, then the Simulation Data Inspector is available for you.
Now the Simulation Data Inspector is another capability I want to highlight because even though it has been around for a few years, we keep adding new capabilities to make it more powerful and more flexible for you. For example, one of the latest updates is the ability to visualize signals as sparklines. You can stack signals or multiple signals in the same subplot. And when there are a lot, you get this scrollbar here to see all of them.
You can also visualize scatter plots as xy plots, and that lets you see the relationship between two signals. So for example here, I'm selecting the motor speed and the motor torque and I can visualize that as a scatter. I can also replay the simulation when I need to share the insights. And in this way the person that receives the data, they can just replay that data. They don't have to rerun the entire simulation. And you can also generate interactive HTML reports.
And when it comes to comparing results across simulation runs, you can actually compare individual signals or you can compare entire runs. And you do that with just a few clicks, no need to write any code for that. Now, if you need to automate the analysis and you need to write the code, then the Simulation Data Inspector has an API that you can use for that. So those are some of the new capabilities that you now have available for analyzing simulations.
Moving on, let's talk about new capabilities for sharing your models. And that's important because once you've analyzed your simulations and your models, others may need to look at your work as well. And what I want to cover here are Dashboard blocks. And these Dashboard blocks give you a way to focus your attention and your interactions in the parts of the model that matter the most to you, or to those that you're sharing your models with. And so instead of having to go deep into all the details of the system, you focus again your attention to the parts that truly matter.
And here is an example. So I can change the engine speed in this model. We're using the sldemo_fuelsys example that is included with the product. So here I change the engine speed and you can see the reactions to that. At the same time here, I can change other parameters to insert failures and see how my system reacts to that. Now in case you didn't notice, this is the same mechanism that we're using in our checklist model. And I also want to highlight that there are switches, LED lights, scopes, gauges, and also customizable gauges that you can fully customize the appearance of. For example, you see that with the engine temperature and also this pressure gauge that I have here.
An advantage of these Dashboard blocks is that you can actually group them together and you can turn them into a panel. A great thing when you turn them into a panel is that now this panel comes with you to different levels of the model hierarchy. And that can save you time when you're troubleshooting at different levels. And right now you see the Dashboard is relatively big, so I can double-click to minimize it. And then it's still visible, but it takes up a lot less space, and I can continue building or editing my model. So that is one great capability for sharing your models.
Now let's move on to integrating external components. Now we're in the second section of the presentation, which is about capabilities for collaborating with others. With Simulink you can reuse existing functionality from multiple tools, and also from other languages. And that makes Simulink a great simulation integration platform, the place where you can design and implement things made out of multiple components and systems like the ones that you see here.
In the last few years, you've been getting more options that make it easy to integrate C and C++ code into your models. For example, the C Function block helps you in the use cases when you need to call multiple functions, allocate or deallocate memory, preprocess or postprocess the external code, and work with persistent data. In 18b we introduced the C Caller block, and this is perfect for use cases when you just need to call C or C++ functions from external source code in libraries, and it's a really simple way to do that with this block.
One of the other advantages of the C Caller block is the tight integration with our other tools like Simulink Coverage, Simulink Test, Simulink Design Verifier, and Simulink Coder for verifying and implementing your models that include that external code. And more recently we added the Simulink Code Importer, which is a user interface that makes it easy to create libraries of C Caller blocks, the one from 18b that I just mentioned. And that gives you a UI that makes it easier to bring that custom code in your models.
And so the Code Importer, it guides you step-by-step to import the code, it also analyzes the code automatically, and then on the other side you basically get a Simulink library of blocks that behave the same way. And with Simulink you can actually integrate more than just C and C++ code in your models. In fact, FMU Import and Export have been around for a few years to help you work better with those components from other tools.
And if you need to build and manage your own Blocksets, perhaps you're part of a tools group, then the Blockset Designer helps you do that. You start with code templates that we provide, then you design, build, and test the custom blocks you need. And you can package them as a toolbox to share with all other users in your organization. And you can import existing Blocksets to maintain them going forward with Blockset Designer, or you can actually build brand new block sets with this tool.
So those are some of the new ways that you can integrate external components in your models. And it's also worth mentioning that you have the full power of S-Functions and the S-Function Builder, which have been around for a while. But these new ways that I'm shown here simplify things a little bit. So those are capabilities for integrating external components.
Now let's talk about managing complexity. And here I want to start with projects because projects give you a way to organize, manage, and share your code and models. It's a nice way to contain your work in a single environment, an interface that works with both MATLAB and Simulink. I'll start by opening the Airframe Example project. There you saw that the project environment is automatically set, so things like functions that need to run on start up and setting the project path, all those happen automatically.
You can also customize shortcuts to files and functions that you use frequently. And projects give you all sorts of advantages like options for sharing your work from email to GitHub to FMUs. Also dependency analysis and management tools. There are checks that help upgrade your work to newer MATLAB releases. We also talked about automatic environment configuration options. And there's also source control integration.
One of the things that I want to cover is in the source integration area. So now you can automerge branches that have changes in different subsystems of the same Simulink model file. So if we open the branches view it shows us that Branch2 is the current branch. And I can view specific branches.
For example in Branch2 here, Bob in my team made some changes to the analog control model. And in Branch1, Alice made changes to the same model but in a different subsystem. And I can merge those changes with just one click. And if you need to review and approve changes, then you can still do diff and merge in the pane here on the right. OK, so that's automerge for improving teamwork close with source control.
Projects also help you share your work with colleagues using older MATLAB releases. You can actually export all the files in a project with just one function, which is Simulink.exportToVersion. And the first input is the project to export. The second input is the name of the output file. And the third input is the release you want, and you can go back up to seven years. You see it gives you warnings if you have functionality that wasn't supported in the old release, so you can adjust accordingly. And when it's complete you see the zip file in the current directory.
Another great thing about projects that I want to highlight is the ability to do dependency analysis. And the Dependency Analyzer shows you the relationship between files and you can filter by file type. In this case, I'm only viewing models and data files. And I can focus the view only on the required or impacted files for a portion of my design. And I can package that subset of my design or share a report on it for people that are interested only in those components.
Last but not least if I open this model the Nonlinear Actuator, with projects you can also protect your IP when you share your work with suppliers or other groups. So when you save a model as a protected model, you now have this option to also package all the dependencies in a project. So if we do that, and we go to the designated folder, we extract the archive that was generated, you see that it packaged only the files that we selected, it protected our design, and it also generated a test harness model that your supplier can use to run the model but still keeping your IP safe.
OK, so those are a few new capabilities in projects. And now we can close the project and open up another example about subsystem reference and model comparison, which are tools to manage complexity as you componentize and collaborate with others. In this case, we'll use the sfcar example. And in the first instance, I'm going to make this subsystem a subsystem reference.
I do that by just selecting it in the model, and then in the tool strip I can convert to a subsystem reference. Click Convert, save the changes, and here we see the reference subsystem file. So this gives you a new way to componentize your design in addition to libraries and model references. And for specific guidelines for which method is best for your use case, I encourage you to check out the documentation or some of our other videos.
OK, now if we open this script and run the model comparison, we've added major improvements to this tool to make it easier to distinguish differences between models. And you see that with the highlights as I click through specific elements in the list. So those are new capabilities for managing complexity. Now let's move on to packaging simulations. What that means is that you can create apps, web apps, and FMUs for models using Simulink compiler.
For example if we take this model of a mass spring damper system, and we could package this into an app to share the insights of the simulation, while letting users tune the inputs and parameters and also monitor the outputs. So if you look at the MATLAB app interface that comes with the example, you see we can add pictures, edit controls for the parameters, scopes for the outputs, and we can make the buttons simulate the model. If we switch to the code view of this design, there you see the code that runs when the button is pressed, those are the parameters used, and there you see the sim function that runs the model.
When we run the app, we get the standalone view, and I can press the button to test. And also here's what the web app version looks like. I can access and run this from a web browser. So again you can package simulations, so standalone apps, web apps, and FMUs. So that was a quick overview of Simulink Compiler, but that's a new exciting capability for packaging, deploying, and sharing your simulations with colleagues, and collaborators, and suppliers as well. So now we can check that off our list.
All right, so this is the third and last section of the day. And here I'm going to cover resources that can help you stay up-to-date and learn more about the latest capabilities that are coming to Simulink. The first resource I want to cover you can access right from MATLAB. In fact, if you go to the MATLAB Home tab in the tool strip, and select the Add-Ons dropdown, we can get add-ons.
And in the Add-On Explorer, which is this interface that you see now, you get access to MathWorks toolboxes and products, but also you get access to toolboxes that are authored by the community. In fact, there are over 1,300 of them, as you see here. And there are also community apps, community Simulink models, and a lot more. And you can apply multiple filters to find some of the models or toolboxes that somebody may be using for problems that you may be trying to solve.
One thing I want to highlight as well is these filters by type, and I want to focus on the hardware support packages. And these hardware support packages are a key piece when you want to connect MATLAB and Simulink with specific hardware. And so you'll find support packages for low-cost hardware options like Arduinos, Raspberry Pis, and a lot more. And for example, you can also filter by Simulink support packages. You see the ones for Parrot Minidrones, LEGO Mindstorms, and a lot more. So I encourage you to check out the add-ons for community tool boxes and models and also for the hardware support packages.
Another resource I want to highlight is the community. MATLAB and Simulink have a really strong community. And what you see here is the MATLAB central page. And from here you can access MATLAB answers, so users just like you asking questions and the responses are given by other users and also for MathWorks experts. Here you also have File Exchange, is just a big repository of community models and programs. And so if you're trying to solve a problem, this is a great place to check in case somebody already has solved that problem as well. And so that is MATLAB Central.
And another resource I want to highlight is Simulink Online. So Simulink is now accessible right from your website browser. No need to download or install anything. So if you just web search Simulink Online, you will find this page. And if you click that and you're eligible, then you can actually get access to it. So I already have this tab open, and what you see here is MATLAB from my web browser. So I can just click on Simulink here, and what you see is the Start Page. So I can just open up a new model, my recently used models, or an example.
At the same time I will also want to highlight Onramps, specifically the Simulink Onramp. So these Onramps are free tutorials that take about two hours to complete, but again you can save your progress and you don't have to do it all in the same sitting. So I encourage you to check those out. There are Onramps for Simulink, Stateflow, Simscape, Control Design, Deep Learning, and a lot more.
So I have the Onramp open and I can show you that. So here is the navigation page. So here's my progress and right now I'm in the Running Simulations section. And what that looks like is like this. I have three panes. The one on the left is the task that I have to complete. In the middle, I have the canvas where I do the work. And on the right, I get the assessment feedback that keeps me learning the product and making progress. So that is the Onramp.
Another resource I want to highlight is the release notes. And here is where you can get all the details about what is new in Simulink and all the other products. I'm already in the release notes for Simulink, and you see that you can filter by multiple categories. You can also apply text filters if you're interested in specific topics. And you can also expand or constrain your search to a specific range of releases. And so when you click on a specific release note it tells you exactly the details about what's new in that area, so a great way for you to learn that.
And the last thing I want to cover as well is the Upgrade Advisor. If you are working in Simulink you do have access to a tool that helps you upgrade and make that process easier for you. So here's the documentation page for that. I encourage you to take a read. And you can use this function, or if you're using projects which we covered today, you can also upgrade from that. And if you click on that link, it takes you to this page and it gives you more details about how to upgrade from a project.
That is the last capability that I have for today. So now we can go back to our checklist and keep track of our progress, so we covered all of these. And at this time I want to thank you for your time and for your attention.