Azzera filtri
Azzera filtri

Save Simulink subsystem output as constant

27 visualizzazioni (ultimi 30 giorni)
Andrew Poissant
Andrew Poissant il 27 Giu 2017
Commentato: Andrew Poissant il 29 Giu 2017
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?

Risposte (1)

Swarooph il 27 Giu 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 Commenti
Swarooph il 28 Giu 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?
Andrew Poissant
Andrew Poissant il 29 Giu 2017
1. It must be a single not updating with time because the simulink block that I am sending the value to expects a single vector, not one that is updating. Otherwise I get an error.
2. Sorry for the confusion. I want to use this in the rest of the model but the point I was making is that all I want to do is save the output of this Simulink as a single vector and then not have simulink "updating" it with time. So my output of the Simulink looks like [1.001, 0.001] at t=0, [1.001, 0.001] t=1, etc. But I simply want just [1.001, 0.001].

Accedi per commentare.


Community Treasure Hunt

Find the treasures in MATLAB Central and discover how the community can help you!

Start Hunting!

Translated by