strfind in simulink and stateflow

hi all,,
i have condition using strfind in simulink and embedded matlab function.
here is my EMF:
function V=sequence(x)
correct= @(x)any(strfind((x)>4,[1 1 1 1 1]))
if correct(x)
V=10000;
else
V=1
end
  • my input from simulink are:[5 5 5 5 5 1 1 1 1 1 2 2 2 2 2 3 3 3 3 3]
  • the output: V=1
  • supposed V=10000
why it keeps telling me not the correct answer based on my condition????
what about in stateflow???
thanks

 채택된 답변

Luhur
Luhur 2011년 7월 11일

0 개 추천

the correct one is:
function V=sequence(x)
%#codegen
correct= testinput(x);
if correct
V=10;
else
V=1;
end
function correct = testinput(x)
eml.extrinsic('strfind');
correct = any(strfind((x')>4,[1 1 1 1 1]));
THANK YOU SO MUCH EVERYONE!! :)

추가 답변 (3개)

Kaustubha Govind
Kaustubha Govind 2011년 7월 7일

1 개 추천

Do you mean that you expect V=10000, but you actually get V=1? I don't know what you've done differently, but after changing your code to fit Embedded MATLAB restrictions, I got 10000 as output from the Embedded MATLAB Block:
function V=sequence(x)
%#codegen
correct= testinput(x);
if correct
V=10000;
else
V=1;
end
function correct = testinput(x)
coder.extrinsic('strfind');
correct = any(strfind((x)>4,[1 1 1 1 1]));

댓글 수: 2

Luhur
Luhur 2011년 7월 7일
my simulink shows error:
Undefined variable "coder" or class "coder.extrinsic".
Luhur
Luhur 2011년 7월 9일
not
coder.extrinsic('strfind');
but
eml.extrinsic('strfind');
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 1 1 1 1]));
but still tell error:
Embedded MATLAB Interface Error: Error using ==> strfind
Input strings must have one row.
Block Embedded MATLAB Function (#32)
While executing: none

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

Paulo Silva
Paulo Silva 2011년 7월 7일

1 개 추천

if any(strfind((x)>4,[1 1 1 1 1]))
V=10000;
else
V=1
end

댓글 수: 5

Luhur
Luhur 2011년 7월 7일
are you using embedded matlab function paulo???
not works for me...
Paulo Silva
Paulo Silva 2011년 7월 7일
you have to declare any and strfind extrinsic functions, I didn't test the code
Luhur
Luhur 2011년 7월 9일
i already did, like this:
function V=test(x)
eml.extrinsic('strfind');
if any(strfind(x>4,[1 1 1 1 1]));
V=10000;
else
V=1;
end
shows error:
Embedded MATLAB Interface Error: Error using ==> strfind
Input strings must have one row.
Block Embedded MATLAB Function (#32)
While executing: none
Luhur
Luhur 2011년 7월 9일
test the code please.. :)
Luhur
Luhur 2011년 7월 9일
test the code please.. :)

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

Luhur
Luhur 2011년 7월 7일

0 개 추천

nope, its a strfind, the condition will true if the value is in sequence 5 time a row and also bigger than 4...

카테고리

도움말 센터File Exchange에서 Simulink Functions에 대해 자세히 알아보기

질문:

2011년 7월 7일

Community Treasure Hunt

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

Start Hunting!

Translated by