changeble patern on strfind in embedded matlab function or stateflow
이전 댓글 표시
hi all,,
my previous post http://www.mathworks.com/matlabcentral/answers/11244-please-help-strfind-in-stateflow-not-yet-solved talk about strfind with exact pattern:
correct = any(strfind((x')>4,[1 1 1 1 1]))
what if during the x value change, the pattern change too,, for example:
from:
correct = any(strfind((x')>4,[1 1 1 1 1]))
become:
correct = any(strfind((x')>4,[1 1 1 1 1 1 1]))
while the x value increase from 5 to 8,
then the pattern change again if the x value increase from 9 to 12.
become:
correct = any(strfind((x')>4,[1 1 1 1 1 1 1 1 1]))
how we do it on Embedded matlab function or STATEFLOW???
thanks.
채택된 답변
추가 답변 (5개)
Luhur
2011년 7월 11일
댓글 수: 3
Fangjun Jiang
2011년 7월 11일
Did you feed a value (e.g. Constant 6) to the second input n?
Luhur
2011년 7월 11일
Fangjun Jiang
2011년 7월 11일
Try put a fixed number first to see if it passed, like correct = any(strfind((x')>4,ones(1,6))) in your EML code. Then add a data type conversion block between your slide gain block and the EML block. I wonder if it requires n to be explicitly specified as an unsigned integer.
Luhur
2011년 7월 11일
0 개 추천
댓글 수: 4
Fangjun Jiang
2011년 7월 11일
All I can say is to double check everything. Did you save after modification?
Luhur
2011년 7월 11일
Fangjun Jiang
2011년 7월 11일
It's getting harder and harder for me to understand your question. Can you write it in a complete sentense?
Fangjun Jiang
2011년 7월 11일
If you run it in MATLAB directly, it gives correct result. I suspect you made mistake somewhere else. That's why I asked you to double check everything.
x=[1 2 5 5 5 5 5 2 6 6 6 6 6 2 1 1 2 1 1 2]';
n=10;
correct = any(strfind((x')>4,ones(1,n)))
correct =
0
Luhur
2011년 7월 11일
0 개 추천
댓글 수: 4
Fangjun Jiang
2011년 7월 11일
The answer is YES. If n=2, then when x has 2 or more consecutive value that is great than 4, correct will return TRUE.
Luhur
2011년 7월 11일
Fangjun Jiang
2011년 7월 11일
In the case of n=2, x=[5 5 1 5 5], should it return TRUE or FALSE?
Luhur
2011년 7월 11일
Fangjun Jiang
2011년 7월 11일
TRUE when there is one and only one exact number of consecutive values greater than 4.
correct=length(strfind((x')>4,ones(1,n)))==1
TRUE when there is exact number of consecutive values greater than 4, multiple occurrence is allowed, however, more consecutive values greater than 4 will result in FALSE.
correct=or(isempty(diff(strfind((x')>4,ones(1,n)))),all(diff(strfind((x')>4,ones(1,n)))>1))
I realize that I don't have to make it an one-liner. Using the following two lines is better for readability.
correct=diff(strfind((x')>4,ones(1,n)));
correct=or(isempty(correct),all(correct>1));
카테고리
도움말 센터 및 File Exchange에서 Simulink Functions에 대해 자세히 알아보기
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!