

Otherwise, since the two subsystems are identical, the coder generates a reusable function. ***Note: To obtain the above code, I manually set the Function Packaging option of the If Action Subsystem to Inline. Otherwise the threshold of the switch is a tunable parameter.

***Note: To obtain the above code, I enabled inline parameters from the model configuration.
#LOGICWORKS CIRCLE CODE#
to make the code easier to read for this post, I set the storage class of the three signals or interest ( hold, u, y) to ExportedGlobal. In this case, all the methods generate similar code. I will let you judge by yourself which implementation most clearly shows the intention of holding a signal.Īnother concern that many users have is: What does the code look like? One of my favorite guidelines for was suggested by a reader of this blog: Clearly show the intended functionality. When choosing an implementation, many factors need to be taken into account. Personally, I don't use this syntax very often, mostly because it requires more blocks.Īnother easy way to obtain the behavior we are looking for is using Stateflow This version is similar to the first method, but we replace the Switch by an arrangement of If Action Subsystems and a Merge block. I like this method because it takes virtually no blocks. Personally, my favorite way to hold a the value of a signal is using an Enabled Subsystem, with the Outport property Output when disabled set to held. The most common way to hold a value that I observe in customers models is using a Switch and a Unit Delay, or Memory block Let's see a few ways to obtain such behavior Here are example input and output signals: When hold is zero, the output y remains constant, holding the last output value. When hold is true, the output y is equal to the input u. I want to create a subsystem with two inputs, u and hold, and one output y. I made him a few examples that I am sharing today in this post. Of course, my answer was that there are many ways to hold a value in Simulink.
#LOGICWORKS CIRCLE HOW TO#
Yesterday, I was giving a training to new hires at MathWorks and one of the attendees asked me how to hold a value in Simulink.
