Save Simulink subsystem output as constant
22 views (last 30 days)
Show older comments
I have a simulink system with multiple subsystems. In one subsystem, I want the output to be a constant singlular value not updating with time. Simulink naturally has the value updating with time but I want to save the first value as a constant to use elsewhere in the simulation. Basically like a specified constants block. Any ideas on how to stop the output from updating with time?
0 Comments
Answers (1)
Swarooph
on 27 Jun 2017
There are a couple of ways to do this based on what you feel comfortable with.
1. Using MATLAB Function block:
Here we declare a persistent variable in a MATLAB function block and initialize it during the start of the simulation, and set the output to the same value and never update the persistent variable again. So the output of the block is basically the initial value of the signal. Some screenshots of this approach below and example model holdInitVal_MLFunc.slx in the zip attached.
2. Using Triggered Subsystem block:
Here we use a triggered subsytem (set trigger to either), generate a trigger signal based on when the Clock block is == 0. So when this condition is satisfied, the subsystem is triggered to pass the output equal to the input which is only during the start of the simulation. Thus holding the output value for the rest of the simulation. Some screenshots of this approach below and example model holdInitVal_TrigSubs.slx in the zip attached.
My 2 cents: I think approach 1 is cleaner and easier to follow. If you are new to MATLAB function blocks, here is a quick intro.
3 Comments
Swarooph
on 28 Jun 2017
I would argue that putting a scope on a constant block also shows the value as a function of time. But that is besides the point. I have a couple of follow up questions:
1. Why does it matter if the value is updated to the same value as long as it is the same? It seems like we don't have the full picture of what you are trying to do. Perhaps if we have that, we could suggest better ways of doing this.
2. You say
Another way to think about it is you can take a predefined vector in
matlab and use it in simulink but it is not updated at all. I want to
do that but instead of inputing the vector I want to output it. Again,
only a single vector, not many vectors corresponding to each time step.
I don't understand this tbh. Are you trying to hold the initial value of a signal as a constant or not? And do you want to use this in the rest of the model at some point or just output it to the workspace?
See Also
Products
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!