MATLAB Answers

Save Simulink subsystem output as constant

Andrew Poissant 님이 질문을 제출함. 27 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?

  댓글 수: 0

로그인 to comment.

답변 수: 1

回答者: Swarooph
2017 年 6 月 27 日

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

Andrew Poissant 2017 年 6 月 27 日
This is close to what I want but I want to define the output at a constant value but not updating that same value every time interval, so it is not a list of the same constant value, just a single point. If you put a scope on a constants block it outputs a single point and then nothing else. 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.
Swarooph
2017 年 6 月 28 日
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 2017 年 6 月 29 日
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].

로그인 to comment.



Translated by