MATLAB Answers

Simulink block to get the specified value

조회 수: 12(최근 30일)
A
A 2021년 9월 5일
편집: Andy Bartlett 2021년 9월 7일
Is there a block that can get the initial value or specified value from the signal?
If there is a way to find the value from a specified index, please let me know.
  댓글 수: 6
A
A 2021년 9월 6일
Sorry for the confusion.
a. That's right.I want to take the value of a waveform at a certain time, and use that value (fixed value) as input for another block.
b. I wrote "index" as an image to specify the order of the values, like M rows and N columns. I think the usage is wrong. So, please don't worry about it.
I thought it would be useful if I could specify an arbitrary order of the values, such as getting the first value output from a waveform.

댓글을 달려면 로그인하십시오.

채택된 답변

Paul
Paul 2021년 9월 6일
One option to grab the value of a signal at a certain time and hold it afterwards is to pass it through a Triggered Subsystem, where the trigger signal is based on the time you want to grab the value. Like this:

추가 답변(1개)

Andy Bartlett
Andy Bartlett 2021년 9월 7일
편집: Andy Bartlett 2021년 9월 7일
You need your design to remember the past value of a signal, so your design will need some lasting memory. Lasting memory is also called state. The simplest way to get memory for a discrete-time model is to use a Unit Delay or Delay block.
You want to latch a signal value at a particular time, so you'll need to create a true/false signal that indicates value true when you want the latching to happened and false at all other times.
You can then use a switch block to control whether the new signal value goes into the delay block or the delay block output is fed back into itself. This figure shows the basic idea where the signal labelled Enable is the true/false control signal.
There is a subtle, but important choice of whether it is OK to get the latched value after one unit delay time step or immediately with zero delay. The image above will involve a one time step delay. If you need zero delay, then change the design to feed the signal labelled Xnew as the output instead of Xold.
Since you want to capture the very first value of the signal, you want an enable signal that is true at the beginning of simulation and always false after that. A constant and the good old unit delay can do this as shown in this image. A key is that the first output of the unit delay is its initial condition which is 1. After that, the delay's output will be its prior input which is always 0.
A model showing both the one time step delay and zero time step delay is attached. It works with R2013a and newer.
Note the delay blocks shown are custom examples and are not the Delay block provided by Simulink. Click to select each block of these custom delay blocks one at a time, then do Crtl-U to look at what is underneath their masks. That will be informative.
The two sets of outputs look like this.
Where the yellow signal is the one to be captured at a specific moment.
The green-ish signal is the true-false control signal for when the latching action is to happen.
The magenta is the captured and held signal.
Note, the sample times for all the blocks are 1 second..

Community Treasure Hunt

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

Start Hunting!

Translated by