How to detect sequence signal explicitly

조회 수: 2 (최근 30일)
Luhur
Luhur 2011년 7월 13일
hi all
let say i have vector signal V (1x5): V=[2 4 1 7 9]
how we can get in which position is our signal:
for example, by V, then 4 is signal number 2 or 9 is signal number 5. how we can get like that in simulink???
thanks

채택된 답변

Doug Eastman
Doug Eastman 2011년 7월 13일
If you are using R2010a or later you can use the Relational Operator block in Logic and Bit Operations to compare the vector V and the signal S using the == operator, then send that output to the Find Nonzero Elements block in Math Operations.
  댓글 수: 2
Luhur
Luhur 2011년 7월 13일
why find non zero element in math operation??? i just want to get the positio of the signal.
for example:
if value V is the signal, V=[2 4 1 7 9]
and S is the number of signal position, S=[1 2 3 4 5]
let say we after some condition value V that appear is 9, then also appear the number of signal position which is 5 because 9 at the end of signal S which is signal number 5.
get it???
Doug Eastman
Doug Eastman 2011년 7월 13일
From what I understand you want a system with two inputs and one output. One input is a vector (V), say [2 4 17 7 9], the other is a signal (S), say 7. You want the output to be the position of S in V, in this case 4. Is that right?
If so, that's exactly what I'm describing above. The relational operator will output a vector [0 0 0 1 0] where S==V, then the find block will output the index of that location, in this case 4. Make sense?

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

추가 답변 (1개)

Luhur
Luhur 2011년 7월 14일
i see.. but doug, after i tried it, the error in simulink was in find nonzero elements block...
the error was: The signal at output port 1 of 'detect_signal/Find Nonzero Elements' is a variable-size signal with a nondiscrete sample time. The sample time for any variable-size signal must be discrete.
  댓글 수: 2
Doug Eastman
Doug Eastman 2011년 7월 14일
Yes one of the limitations of this block is that it will need to be run with a discrete sample time. Is that acceptable? If so, you can enter the sample time in the block (i.e. enter 0.01 if you want the block to run 100 times a second).
Luhur
Luhur 2011년 7월 14일
nice doug,another alternative. but i prefer the answer in this post http://www.mathworks.com/matlabcentral/answers/11500-detect-smallest-or-bigest-value-of-signal-in-stateflow-and-simulink
THANKS DOUG!!! NICE!!!

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

카테고리

Help CenterFile Exchange에서 Simulink Functions에 대해 자세히 알아보기

Community Treasure Hunt

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

Start Hunting!

Translated by