strfind in simulink and stateflow

2 visualizaciones (últimos 30 días)
Luhur
Luhur el 7 de Jul. de 2011
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

Respuesta aceptada

Luhur
Luhur el 11 de Jul. de 2011
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!! :)

Más respuestas (3)

Kaustubha Govind
Kaustubha Govind el 7 de Jul. de 2011
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 comentarios
Luhur
Luhur el 7 de Jul. de 2011
my simulink shows error:
Undefined variable "coder" or class "coder.extrinsic".
Luhur
Luhur el 9 de Jul. de 2011
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

Iniciar sesión para comentar.


Paulo Silva
Paulo Silva el 7 de Jul. de 2011
if any(strfind((x)>4,[1 1 1 1 1]))
V=10000;
else
V=1
end
  5 comentarios
Luhur
Luhur el 9 de Jul. de 2011
test the code please.. :)
Luhur
Luhur el 9 de Jul. de 2011
test the code please.. :)

Iniciar sesión para comentar.


Luhur
Luhur el 7 de Jul. de 2011
nope, its a strfind, the condition will true if the value is in sequence 5 time a row and also bigger than 4...

Categorías

Más información sobre Simulink Functions en Help Center y File Exchange.

Productos

Community Treasure Hunt

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

Start Hunting!

Translated by