changeble patern on strfind in embedded matlab function or stateflow
1 次查看(过去 30 天)
显示 更早的评论
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.
0 个评论
采纳的回答
Fangjun Jiang
2011-7-11
Have a second input to your EML, say n, feed a constant block with value of 5, 6, 7, etc, or this input could be a varying signal. Inside your EML, you can generate the [1 1 1 1] vector with ones(1,n);
2 个评论
Fangjun Jiang
2011-7-11
Well, that is up to you. From your description, I thought you want to do:
correct = any(strfind((x')>4,ones(1,n))); where n is a varying number, it could be 5, 6, 7, or 12. That's what you want, right? You could make n the second input of your EML, change those lines accordingly,
function V=sequence(x,n)
correct= testinput(x,n)
function correct = testinput(x,n)
更多回答(5 个)
Luhur
2011-7-11
3 个评论
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
4 个评论
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
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));
另请参阅
类别
在 Help Center 和 File Exchange 中查找有关 Simulink Functions 的更多信息
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!