detect smallest or bigest value of signal in stateflow and simulink
14 views (last 30 days)
Show older comments
hi all..
let say i have 2 signal, first signal is the value (let say S) and second signal is the number of value (let say N), both are vector signal with 10 element(vector(1x10))
S=[3 4 5 7 8 9 11 12 13 14]
N=[1 2 3 4 5 6 7 8 9 10]
and then, i have signal C,
C=20
how if i want to detect the smallest and the biggest gap between element C and S,
for example: let say H was the value off gap between S and C: H= C-S then result H
H= [ 17 16 15 13 12 11 9 8 7 6 ]
how we detect the smallest and the bigest value H, then show the number signal it was from.
example in this case,according H value: the smallest= 6, number of signal= 10 the biggest= 17, number of signal= 1
how we do it in STATEFLOW, SIMULINK OR EMBEDDED MATLAB FUNCTION ??
THANKS,
0 Comments
Accepted Answer
Fangjun Jiang
on 14 Jul 2011
Okay, it can be done in Simulink, if you can follow me here. Drag a Constant block, put in [3 4 5] as its value, label its output as "S" so we can refer to it here in the post. Feed "S" to a MinMax block, label its output as "MinS". Feed "S" and "MinS" to a Relational Operator block, select "==" as the operator, label its output as "EqualS", feed "EqualS" to a Data Type Conversion block, label its output as "DoubleS". feed "DoubleS" to the first input of a Dot Product block, the second input of the Dot Product block is a Constant block with its value as [1 2 3].
Hook a Display block to the output of the Dot Product block, run simulation you will see its value is 1, which means the first element of "S" is the minimum, which is correct. Change the value of "S" to be [3 2 5], the result will be 2. Change "S" to be [3 2 1], the result will be 3.
2 Comments
Fangjun Jiang
on 14 Jul 2011
Hope you can expand it to be used for maximum. If you S has more element, for example, 10. Make sure the value of the second Constant block is [1:10].
More Answers (2)
Fangjun Jiang
on 13 Jul 2011
S=[3 4 5 7 8 9 11 12 13 14];
C=20;
H=C-S;
[MinVal,MinInd]=min(H)
MinSignal=S(MinInd)
[MaxVal,MaxInd]=max(H)
MaxSignal=S(MaxInd)
4 Comments
Fangjun Jiang
on 13 Jul 2011
The MinMax block is the right one to use. I have to ask you to clarify what do you mean signal here. When you say S=[3 4 5 7 8 9 11 12 13 14], do you mean the value of the signal S is 3 at time=0, 4 at time=t, 5 at time=2*t, etc? t could be any time step like 0.1 sec or 0.001 sec. The other meaning could be S is a vector signal with 10 elements. The first element is 3 all the time, the second element is 4 all the time, etc. The way you put S in a constant block makes it take the latter meaning. Is that what you really want?
See Also
Categories
Find more on Simulink Functions in Help Center and File Exchange
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!