sandy3129
Member level 3
hello guys I'm trying to understand how to implement state machines using matlab function in simulink, can anyone let me know what the meaning of this statement
" persistent state , state = x1_state(start, {x1unsigned, 2,0});" in the following code????
Thanks in advance.
" persistent state , state = x1_state(start, {x1unsigned, 2,0});" in the following code????
Thanks in advance.
Code:
function matched = detect_1101(d_in)
start= 0;
found1=1;
found11=2;
found110=3;
persistent state , state = x1_state(start, {x1unsigned, 2,0});
matched = 0;
switch state
case start
if d_in ==1
state = found1;
else
state =start;
end
case found1
if d_in ==1
state = found11 ;
else
state =start;
end
case found11
if d_in ==0
state = found110;
else
state =found11;
end
case found110
if d_in ==1
state = found1;
matched = 1;
else
state = start;
end
otherwise
state = start;
end
end