MATLAB Fast Automation: Tired of Working? Here's Your Step-by-Step Action Plan to Automate Your Work With MATLAB.
This article illustrates the basic model-based design mistakes made in Simulink that the function checkModel (from the previous related article) will address.
Here’s the model we’ll take as an example, “mySimpleModel.slx.”:
Modifying The Model
Let’s modify the model “mySimpleModelLib.slx” by disabling the “Subsystem” library block. If you don’t know how to do that, you can refer to:
Simulink Tutorial: How to Modify a Library Block
The library is now disabled, as we can see with the small lock at the lower left the library block:
Now, if we run the function checkModel on mySimpleModel.slx:
Next, lock the library and try again (if you don’t know how to do that, refer to the article about modifying libraries):
If you followed this step exactly as I did, you didn’t save your model after resolving the link between your model and the library. Predictably, the function generates an error. If we save the model and run the function again, here’s what happens:
- The workspace is cleared.
- The model closes.
- The model opens again and successfully simulates.
Now, let’s say we want to set up the duration of your simulation by defining a variable “t” as explained in the following article: Simulink Tutorial: Run a Simulink Model from MATLAB
Let’s define the variable “t” to 5s in the workspace:
If we save the model and run the checkModel function again, we get:
Since the variable was not defined when the model opened, the function checkModel generates an error. So, let’s define the variable “t” every time the model opens:
- File > Model Properties > Model Properties
- Define the variable “t” in the “Callbacks” tab as follows:
- Click “Apply” and “OK”
After saving your model and running the checkModel function again, no errors are generated, which means that you successfully created a clean model. Congratulations!