detect smallest or bigest value of signal in stateflow and simulink

14 Ansichten (letzte 30 Tage)
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,

Akzeptierte Antwort

Fangjun Jiang
Fangjun Jiang am 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 Kommentare
Fangjun Jiang
Fangjun Jiang am 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].

Melden Sie sich an, um zu kommentieren.

Weitere Antworten (2)

Fangjun Jiang
Fangjun Jiang am 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 Kommentare
Luhur
Luhur am 13 Jul. 2011
how we do it in simulink without EMF fang?? i already use MIN and MAX block, and now i dont know how to detect which number of signal it was in simulink.
Fangjun Jiang
Fangjun Jiang am 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?

Melden Sie sich an, um zu kommentieren.


Luhur
Luhur am 14 Jul. 2011
i mean yes all the time fang.. later it will change by slider gain..
if S=[3 4 5 7 8 9 11 12 13 14] *S is signal value that change by slider gain
N=[1 2 3 4 5 6 7 8 9 10] *N is also signal value but not change,because it shown the sequence of the signal S.
so, in S, 3 means signal number 1, 4 means signal number 2, 5 means signal number 3 etc...
the case was like in the original question, please refer to it..

Kategorien

Mehr zu Simulink Functions finden Sie in Help Center und File Exchange

Community Treasure Hunt

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

Start Hunting!

Translated by