changeble patern on strfind in embedded matlab function or stateflow

hi all,,
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.

 採用された回答

Fangjun Jiang
Fangjun Jiang 2011 年 7 月 11 日

1 投票

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 件のコメント

Luhur
Luhur 2011 年 7 月 11 日
what if the x value that change fang???
x value change (for example increase) then the pattern also increase (for example: from [1 1 1 1] become [1 1 1 1 1 1]????
how its gonna be?? like this??
function V=sequence(x)
%#codegen
correct= testinput(x);
if correct
V=10000;
else
V=1;
end
function correct = testinput(x)
eml.extrinsic('strfind');
correct = any(strfind((x')>4,[1,n]));
(how we manage to control the n value of the pattern??? is it give another input from simulink???)
Fangjun Jiang
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
Luhur 2011 年 7 月 11 日

0 投票

SORRY... NOT X CHANGE, BUT ANOTHER VARIABLE, LET SAY Y...
Luhur
Luhur 2011 年 7 月 11 日

0 投票

i use this in my EMF fang:
function V=sequence(x,n)
%#codegen
correct= testinput(x,n);
if correct
V=10;
else
V=1;
end
function correct = testinput(x,n)
eml.extrinsic('strfind');
correct = any(strfind((x')>4,ones(1,n)));
and still error. it was shown:
*Computed maximum size is not bounded. Static memory allocation requires all sizes to be bounded. The computed size is [1 x :?].
Function 'Embedded MATLAB Function' (#37.186.195), line 11, column 30: "ones(1,n)" Launch diagnostic report.*

3 件のコメント

Fangjun Jiang
Fangjun Jiang 2011 年 7 月 11 日
Did you feed a value (e.g. Constant 6) to the second input n?
Luhur
Luhur 2011 年 7 月 11 日
yes, constant 6, 8, 9 it can be change because i use slider gain fang.
Fangjun Jiang
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
Luhur 2011 年 7 月 11 日

0 投票

succeed fang,, but its not in sequence...
for example the value:
[1 2 5 5 5 5 5 2 6 6 6 6 6 2 1 1 2 1 1 2] when n=10 supposed to be false. because there was 2 between it. but the condition said it TRUE.
not in sequence.. so???

4 件のコメント

Fangjun Jiang
Fangjun Jiang 2011 年 7 月 11 日
All I can say is to double check everything. Did you save after modification?
Luhur
Luhur 2011 年 7 月 11 日
oh i see, this function correct = any(strfind((x')>4,ones(1,n)));
was not precise in sequence fang??
for example, if n=8 then the value inside it if there was 10 in sequence value then the condition is correct fang???
not precise must 8 in sequence for example???
Fangjun Jiang
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
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
Luhur 2011 年 7 月 11 日

0 投票

haha.. sorry fang... :D
i mean this condition:
correct = any(strfind((x')>4,ones(1,n)));
will TRUE even the result in sequence is more than the n value.
for example n=2, then [5 5 5 2 2] the condition is TRUE right?? because in sequence more than n=2, value 5 mention 3 times a row. not exact must mention 2 times a row.
right???
what about the condition if we want have exact in sequence. i mean, like in the above: for example n=2, then [5 5 5 2 2] the condition is FALSE, because strict to the condition must only 2 times a row.
get it fang???

4 件のコメント

Fangjun Jiang
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
Luhur 2011 年 7 月 11 日
what if we want exact value fang???
i mean, if n=2, then x only true if it has 2 consecutive value that is great than 4.
how fang??
Fangjun Jiang
Fangjun Jiang 2011 年 7 月 11 日
In the case of n=2, x=[5 5 1 5 5], should it return TRUE or FALSE?
Luhur
Luhur 2011 年 7 月 11 日
if TRUE the code is???
if FALSE the code is???

サインインしてコメントする。

Fangjun Jiang
Fangjun Jiang 2011 年 7 月 11 日

0 投票

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));

1 件のコメント

Luhur
Luhur 2011 年 7 月 11 日
THANK YOU FANG, THANKS AGAIN... :D

サインインしてコメントする。

カテゴリ

ヘルプ センター および File ExchangeSimulink Functions についてさらに検索

Community Treasure Hunt

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

Start Hunting!

Translated by