MATLAB Answers

Save Simulink subsystem output as constant

15 views (last 30 days)
Andrew Poissant
Andrew Poissant on 27 Jun 2017
Commented: Andrew Poissant on 29 Jun 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?

Answers (1)

Swarooph
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
Andrew Poissant
Andrew Poissant on 29 Jun 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].

Sign in to comment.

Community Treasure Hunt

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

Start Hunting!